Reputation: 1150
I'm new to iOS and Its developing.i have read Xcode old style passing data between view controllers.there i have seen lot of things going with xib files.please find below the code i have used to pass data in-between ViewControllers.but there in customelink(please find DetailViewController.m)there I'm getting Null value.please help me to get String value there.and kind enough to explain what are the mistakes I've done here.
EssentialInfoController.h
#import <UIKit/UIKit.h>
#import "DetailViewController.h"
@interface Essentialinfocontroller : UIViewController
@end
EssentialInfoController.m
#import "Essentialinfocontroller.h"
@interface Essentialinfocontroller ()
@end
@implementation Essentialinfocontroller
- (void)viewDidLoad
{
[super viewDidLoad];
DetailViewController * customelink= [DetailViewController alloc ];
customelink.link=@"https://www.facebook.com";
}
@end
DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property(weak,nonatomic)NSString * link;
@end
DetailViewController.m
#import "DetailViewController.h"
@interface DetailViewController ()
@property(nonatomic,weak)NSString *customelink;
@end
@implementation DetailViewController
@synthesize link;
@synthesize customelink;
- (void)viewDidLoad
{
[super viewDidLoad];
self.customelink=self.link;
NSLog(@"link--> %@",customelink);// here 2014-07-06 21:21:51.469 WADTourisum[880:60b] link--> (null)
}
@end
Upvotes: 0
Views: 66
Reputation: 2127
DetailViewController * customelink= [DetailViewController alloc ];
should be
DetailViewController * customelink= [[DetailViewController alloc ] init];
and
@property(weak,nonatomic)NSString * link;
should be
@property(strong,nonatomic)NSString * link;
and log it
NSLog(@"link--> %@",self.link);
you don't need this one
@property(nonatomic,weak)NSString *customelink;
if you use storyboard and segue then you have to implement
-(void)prepareForSegue
method.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
{
// Get reference to the destination view controller
YourViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setMyObjectHere:object];
}
}
assume that you got a button
to move from essentialVC
to detailVC
, in you IBAction
, call this method:
[self performSegueWithIdentifier:@"YOUR_SEGUE_NAME_HERE" sender:self];
this is just a brief answer. I suggest you read about UINavigationController
first, it's much easier to use compared to segue, IMHO.
Upvotes: 1