iphone - Sending NSString to viewController returns a null -
i sent nsstring viewcontroller, tried log viewcontroller, , turned null. code below
edit: im deleting code , showing code application. because still getting (null)
habitviewcontroller.h
#import <uikit/uikit.h> @interface habitviewcontroller : uitableviewcontroller { nsstring *cellname2; } @property(nonatomic,retain) nsstring *cellname2; @end habitviewcontroller.m
@synthesize cellname2; - (void)viewdidload { [super viewdidload]; nslog(@"%@",cellname2); } detailviewcontroller.h
#import <uikit/uikit.h> @interface detailviewcontroller : uiviewcontroller { nsstring *cellname; } @property(nonatomic,retain) nsstring *cellname; @end detailviewcontroller.m
#import "detailviewcontroller.h" #import "habitviewcontroller.h" @end @implementation detailviewcontroller @synthesize cellname; #pragma mark - managing detail item - (void)viewdidload { [super viewdidload]; cellname = @"hello world"; habitviewcontroller *obj = [[habitviewcontroller alloc] init]; obj.cellname2 = cellname; } i left lot of code out, because had nothing problem.
edit
based on jsdodgers comments , answer, have updated question :
habitviwcontroller.h
#import <uikit/uikit.h> @interface habitviewcontroller : uitableviewcontroller { } @property(nonatomic,retain) nsstring *cellname2; @end .m
- (void)viewdidload { [super viewdidload]; nslog(@"%@",self.cellname2); } detailviewcontroller.h
#import <uikit/uikit.h> @interface detailviewcontroller : uiviewcontroller { } @property(nonatomic,retain) nsstring *cellname; @end .m
@synthesize cellname; - (void)viewdidload { [super viewdidload]; cellname = @"hello world"; habitviewcontroller *obj = [[habitviewcontroller alloc] init]; obj.cellname2 = self.cellname; [self configureview]; } but still dont have success. still says (null)
this because have 2 different variables in receiverviewcontroller.
one of them called cellname2, creating through nsstring *cellname2. other called _cellname2 creating through @property(nonatomic,retain) nsstring *cellname2;.
the first can call in receiverviewcontroller through cellname2.... second, can call through either _cellname2... or self.cellname2.
when obj.cellname2 = ..., setting _cellname2, not cellname2. thus, when print cellname2, correctly null have not set yet.
i suggest removing nsstring *cellname2; code. same goes cellname in other class.
Comments
Post a Comment