ios - The value get by delegate method is been clear? -
in tableviewcontrollera.h declare delegate ,and in tableviewcontrollera.m implement method when click cell of tableview, pass value b, , execute perfromseguewithidentifier jump tableviewcontrollb,in tableviewcontrollb.m getting method called, , value, after viewdidload() method call, value become nil. please me solve problem.by way , property of value strong,nonatomic.
dtzhometableviewcontroller.h #import <uikit/uikit.h> #import "passdata.h" @protocol passdatadelegate -(void)passdata:(passdata*) datatoprogram; @end @interface dtzhometableviewcontroller : uitableviewcontroller<uitableviewdelegate,uitableviewdatasource> @property(assign,nonatomic) id<passdatadelegate> datadelegate; @end passdata user-defined class dtzhometableviewcontroller.m -(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { programtableviewcontroller *programviewcontroller= [[programtableviewcontroller alloc]init]; self.datadelegate=programviewcontroller;; passdata *jump=[[passdata alloc]init]; jump.livingstatus=yes; jump.role=0; jump.index=indexpath.row; jump.curonlinenum=305605; [self.datadelegate passdata:jump]; [self performseguewithidentifier:@"showselectedprogram" sender:self]; } programtableviewcontroller.h #import <uikit/uikit.h> #import "dtzhometableviewcontroller.h" @interface programtableviewcontroller : uitableviewcontroller<passdatadelegate,uitableviewdatasource,uitableviewdelegate> @property(strong,nonatomic) passdata * datafromhome; @end programtableviewcontroller.m @implementation programtableviewcontroller - (void)viewdidload { [super viewdidload]; nslog(@"view did load%@",self.datafromhome); // log :null } - (void) passdata:(passdata *)datatoprogram { self.datafromhome=datatoprogram; } @end
delegation isn't proper way pass data segued view controller. instead, want pass data in prepareforsegue:sender:
remove protocol , delegate.
add properties programtableviewcontroller data want pass.
@property (nonatomic, assign) bool livingstatus; @property (nonatomic, assign) nsinteger role; @property (nonatomic, assign) nsinteger row; @property (nonatomic, assign) nsinteger curonlinenum;
in prepareforsegue:sender:
, set programtableviewcontroller's passed properties values associated selected row:
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)__unused sender { if ([[segue identifier] isequaltostring:@"showdetail"]) { nsindexpath *indexpath = [self.tableview indexpathforselectedrow]; programtableviewcontroller *controller = (programtableviewcontroller *)[segue destinationviewcontroller]; controller.livingstatus = yes; controller.role = 0; controller.row = indexpath.row; controller.curonlinenum = 305605; } }
you shouldn't allocate , init programtableviewcontroller in tableview:didselectrowatindexpath:
. segue instantiate destination view controller you.
you don't need have tableview:didselectrowatindexpath:
method. can create push segue tableviewcell programtableviewcontroller, right within storyboard. give segue identifier (such "showdetail"). in prepareforsegue, assign values, explained.
when tap on row, segue create programtableviewcontroller, set parameters, , present you.
Comments
Post a Comment