No visible #interface for 'FirstViewController' declares the selector 'setUIImage' - iphone

first i want to say i have searched for an answer to this error, but none of the answers seems to fit me.
what i am trying to do is pass an uiimage from one vc to another, this is the code that "should" do it. But i get the error "No visible #interface for 'FirstViewController' declares the selector 'setUIImage'"
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"ImageEdit"])
{
FirstViewController *vc = [segue destinationViewController];
[vc setUIImage:image];
}
}

In the interface file for the destinationViewController, do:
#property (strong, nonatomic) NSObject *uIImage;
and in the implementation file for the destinationViewController, do:
#synthesize uIImage;
HTH

Related

Segue after login with facebook ios 6

I'm using Facebook SDK 3.1, my login system is ok, after login in I want to go to other ViewController. I connected both with a segue and the identifier, but now I don't know how I can implement it.
Here, after this:
if (appDelegate.session.isOpen) {
[self.buttonLoginLogout setTitle:#"Log out" forState:UIControlStateNormal];
[self.textNoteOrLink setText:[NSString stringWithFormat:#"https://graph.facebook.com/me/friends?access_token=%#", appDelegate.session.accessTokenData.accessToken]];
}
On my TableViewCell example I'm using it like this:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"test"]) {
NSIndexPath *selectedIndexPath = self.tableView.indexPathForSelectedRow;
RestauranteDetalhesViewController *destViewController = segue.destinationViewController;
destViewController.idRest =[bd.idrestauracao objectAtIndex:selectedIndexPath.row];
}
But here I don't have a indexpath to give to the (id)sender.
Hey Fabio Cardoso there are two types of Segues
Trigger less segue and
Triggered segue
In trigger less segue you just directly drag from one ViewController to another. You dont mention on which action you want the Segue to be done. To do this you need to create segue identifier like you did above. And call the below line in your code.
[self performSegueWithIdentifier:#"YOUR_IDENTIFIER" sender:self];
In second way of segue you directly Ctrl+drag from a button to another ViewController. So no need of writing any code for this. When ever you click on that button it will either do Push, Model or custom segue what ever you selected in storyboard.
When a segue if performed below method is called in the Source ViewController. Here you can write you own code to either pass value from first ViewController to another or any other stuff.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
If there are more than one segue from your ViewController than the identifier will be of use. You can use the identifier like this
if ([segue.identifier isEqualToString:#"YOUR_IDENTIFIER"])
Note: Segue is only one way, so if you create segue from first ViewController to another and if you want to come back (In case of model action) you have to write the delegate method for second ViewController and on clicking the button action call
**FirstViewController.h**
#interface FirstViewController : UIViewController <SecondViewControllerDelegate>
{
}
- (IBAction) buttonTapped:(id)sender;
**FirstViewController.m**
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"YOUR_IDENTIFIER"])
{
SecondViewController *svc_obj = segue.destinationViewController;
svc_obj.delegate = self;
}
}
- (void) buttonTapped:(id)sender
{
[self performSegueWithIdentifier:#"YOUR_IDENTIFIER" sender:self];
}
- (void) secondViewControllerDidCancel: (SecondViewController *) controller
{
[controller dismissViewControllerAnimated:YES completion:nil];
}
**SecondViewController.h**
#class SecondViewController;
#protocol SecondViewControllerDelegate <NSObject>
- (void) secondViewControllerDidCancel: (SecondViewController *) controller;
#end
#interface SecondViewController : UIViewController
{
}
#property (nonatomic, weak) id <SecondViewControllerDelegate> delegate;
- (IBAction)cancelButtonTapped:(id)sender;
**SecondViewController.m**
- (IBAction)cancelButtonTapped:(id)sender
{
[self.delegate secondViewControllerDidCancel:self];
}
#end
I resolved my problem with this simple line:
[self performSegueWithIdentifier:#"begin" sender:self];

calling functions and passing information between views

Thanks in advance for your help!
In the main ViewController.m of my project I am adding a customized tableView like so:
messageController = [[MyMessagesController alloc] initWithStyle:UITableViewStylePlain];
[self addChildViewController:messageController];
[self.view addSubview:messageController.view];
Then, in the MyMessagesController.m section tableView didSelectRowAtIndexPath: I'd like to write code that would take effect in the ViewController.m where it was created and added as a childViewController.
How can I access the functions of the ViewController.m from MyMessagesController.m?
Can I make it a delegate somehow so I could call [delegate functionName];?
Could I pass information back to the ViewController.m? About which of the rows in table was selected by sending through an NSString or NSArray or anything?
Yes, use a delegate, if you are unsure how best to accomplish this, here is a good reference from Apple about delegate programming
Got it figured out, here's how you turn one viewController into a delegate for another:
In the .h of the parent controller -
#interface ViewController : UIViewController <NameOfDelegate> {
In the .m of the parent controller, once you create the new view -
newViewController.delegate = self;
and also:
- (void)functionToCall:(id)sender {
NSLog(#"Function Called!!!");
}
In the .h of the newViewController you're adding -
#protocol NameOfDelegate;
#interface newViewController : UIViewController/OR/TableViewController {
id <NameOfDelegate> delegate;
}
#property (nonatomic, strong) id <NameOfDelegate> delegate;
#end
#protocol NameOfDelegate
- (void)functionToCall:(id)sender;
#end
in the .m of the newViewController -
#implementation newViewController
#synthesize delegate;
and when you're ready to call the function in your delegate -
[delegate functionToCall:self];

How to send data from UItextfields of one viewcontroller to new view controller? [duplicate]

I am a bit stuck on trying to pass data from two UITextfields on one viewcontroller to another viewcontroller. Basically I got the items below:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UITextfield *Textfield1;
IBOutlet UITextfield *Textfield2;
}
-(IBAction)GoNextView:(id)sender;
#end
ViewController.m
#interface ViewController ()
#end
#implementation ViewController
(IBAction)GoNextView:(id)sender {
SecondView *second = [[SecondView alloc] initWithNibName:nil bundle:nil];
[self presentViewController:second animated:YES completion:NULL];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
SecondView.h
#import <UIKit/UIKit.h>
#interface SecondView : UIViewController {
IBOutlet UILabel *ShowTextfield1;
IBOutlet UILabel *ShowTextfield2;
}
-(IBAction)GoBack:(id)sender;
#end
SecondView.m
#interface SecondView ()
#end
#implementation SecondView
- (IBAction)GoBack:(id)sender {
[self dismissViewControllerAnimated:YES completion:NULL];
}
What I want is, that when the button GoNextView is pressed it should pass the data in the UITextfield to the SecondView. And the go to the next page. The data should now be displayed in the two Labels on the SecondView. I've been struggling with this for many hours now and its killing me. I know I have to use some NSString and #property(nonatomic, retain) NSString *asdas. But I simply can't make it work. So based on the above code how do I pass data from the two UITextfield to the two labels on the next view?
Instead of navigating to the second view through a function, use Storyboard Segues. Create a storybaord application. To Create a segue you need a navigation view controller. You can do that by the following steps.
Select the first view controller and go to Editor -> Embed In -> Navigation Controller.
Then Ctrl+Click on the "GoNextView" button, and drag and drop in the SecondView.
You will get three options: push, model, custom. Click push then a segue will be created between these two views.
Click that segue and click the "Show the Attribute Inspector" on the right side property window. Now name it as "connector" or which ever name you prefer.
Now, in SecondView.h create two strings,
#property (nonatomic, retain) NSString *str1;
#property (nonatomic, retain) NSString *str2;
and synthesize them in SecondView.m.
Lets name your UITextFields as "text1" and "text2" which are in your ViewController. Go to the ViewController.h and add #import "SecondView.h"
In ViewController.m do the following,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"connector"])
{
ViewController *VC = [segue destinationViewController];
VC.str1 = text1.text;
VC.str2 = text2.text;
}
}
Now you can display these strings in your SecondView. In Secondview.m,
label.text = str1;
and it will be displayed.
Use NSUserDefaults or the normal synthesising common interface variables. For example,
NSUserDefaults
From sender's view controller,
NSString *text=textField1.text;
NSUserDefaults *prefs=[NSUserDefaults standardUserDefaults];
[prefs setObject:text forKey:#"text1value"];
And you can get the value from any view controller as,
NSUserDefaults *prefs=[NSUserDefaults standardUserDefaults];
NSString *received string= [prefs stringForKey:#"text1value"];
Normal assigners,
I believe you must be using performsegue to navigate view controllers. There is a delegate method called "prepareforsegue" and you can assign the textfield values into the interface variables. For example,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"seguename"]) {
destViewController *destViewController = segue.destinationViewController;
destViewController.name = #"some text";
}
}
In the receiver's view controller, getter variable is actually defined as,
In .h file, #property(nonatomic, strong) NSString *name;
In .m file, Don't forget to synthesis the variable after implementation
#implementation destViewController
#synthesize name;
Hope it helps!

iPhone: How do I share information between my UITabBarViewController and the individual Tabs?

I have a TableViewController that segues into a TabBarViewController.
I know how to pass my object via a segue, but not by a relationship like the TabBarViewController and it's tab share.
How can I do this? From the TabView is there a way to access the TabBarViewControllers member variables?
Update:
This is how I've solved the problem so far, but I'm not crazy about using the AppDelegate to do this...
Add the Following to WhateverYouNamedYourAppDelegate.h
#class myObjectIWantToPass;
#property (strong, nonatomic) myObjectIWantToPass *object;
Then add the following to the View Class file you have your data in that you want to pass on. I'm going to assume you know how to set up your object already in this file if your planning on passing it to another view.
WhateverYouNamedYourAppDelegate *appDelegate =
(WhateverYouNamedYourAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.object = object;
Then you do some similar work to retrieve the object back from the appDelegate in your destination View Class.
WhateverYouNamedYourAppDelegate *appDelegate = (WhateverYouNamedYourAppDelegate *)[[UIApplication sharedApplication] delegate];
object = appDelegate.object;
You can make singleton classes, so that all of the controllers can access those variables in the Singleton. See Code below
SingletonClass.h
#interface SingletonClass : NSObject {
NSString *someString;
}
#property(nonatomic, retain)NSString *someString;
+(id)shared;
#end
SingletonClass.m
#import "SingletonClass.h"
static SingletonClass *aShared;
#implementation LibShared
#synthesize someString;
+(id)shared
{
if (aShared == nil) {
aShared = [[self alloc] init];
}
return aShared;
}
-(id)init
{
if (self = [super init]) {
}
}
-(void)dealloc
{
[someString releease];
[super dealloc];
}
In the tabbar you can set the variable on SingletonClass:
[[SingletonClass shared] setSomeString:#"Value_Set"];
On the tableViewController, you can get the property of the someString variable on the SingletonClass:
NSString *string = [[SingletonClass shared] someString];
There's no need for a singleton pattern here. Instead, you can send the data-object forwards in - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender just as you do normally, you just need to find the correct viewController in the UITabBarController's viewControllers property.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"MyTabBarSegue]) {
UITabBarController *tabBarController = segue.destinationViewController;
// Either set the index here, if you know for sure which viewController is which, or
// Enumerate the viewControllers for isKindOfClass:[MYCustomViewController class] to be robust and change-proof
MYCustomViewController *myVC = [[tabBarController viewControllers] objectAtIndex:0];
myVC.dataObject = self.dataObject;
}
}

Passing an int to a new ViewController

Ive spent a month trying to pass my int to a new view. My int is called score and is connected to a label called scorelab. The user increases the score and once the they run out of time game switches views to game over screen and i would like the users score to be displayed on the game over screen in a label. The game play controller is called GamePlayViewController and the gave over controller is called GameDidEndViewController. I'm tired of trying to get this to work. I have looked at every tutorial possible but nothing seems to work for my case. Please help me i would appreciate it so so much, this is the very last part of game that I need to finish. Thank you in advance!
Sorry here is the code:
GamePlayViewController.h
#import "GameDidEndViewController.h"
int score;
IBOutlet UILabel *scorelab;
GamePlayViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"GameOver"])
{
GameDidEndViewController *vc = [segue destinationViewController];
[vc setscore2: score];
}
}
GameDidEndViewController.h
#import "GamePlayViewController.h"
IBOutlet UILabel *scorelab2;
int score2;
}
#property (nonatomic , assign) int score2;
#property (nonatomic , assign) UILabel *scorelab2;
GameDidEndViewController.m
#synthesize score2 , scorelab2;
-(void)viewWillAppear:(BOOL)animated {
scorelab2.text = [NSString stringWithFormat: #"%d", score2];
[super viewWillAppear: animated];
}
What you do is create a property in GameDidEndViewController to hold the passed in score value.
#interface GameDidEndViewController : UIViewController {
....
}
#property(nonatomic,assign) int score;
#end
Make sure you #synthesize score in the #implementation(.m).
Now when you init and show the GameDidEndViewController you set the score, likely something like this.
GameDidEndViewController *end = .....// init the view.
end.score = score; // assuming you're doing this from GamePlayViewController where it has an int named `score`
Hope this helps !
Here is some tutorial for passing data between ViewControllers using Storyboard:
Storyboards Segue Tutorial: Pass Data Between View Controllers
Tutorial on How-To Pass Data Between Two View Controllers
or use something like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:...]) {
MyViewController *controller = (MyViewController *)segue.destinationViewController;
controller.score = score;
}
}
Hope this helps.