objective c - iPhone: How to add rows in tableview after tabelview already loaded? -
objective c - iPhone: How to add rows in tableview after tabelview already loaded? -
i have implemented "add favourites" functionality iphone application. works fine except adding cells favourite table view during runtime. example, have given next methods.
- (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; tableview.hidden = yes; warninglabel.hidden = yes; // load alter in favourites nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; nsdata *data = [defaults objectforkey:kfavouriteitemskey]; self.favourites = [nskeyedunarchiver unarchiveobjectwithdata:data]; if([self.favourites count] > 0) tableview.hidden = no; else warninglabel.hidden = no; } - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { homecoming [self.favourites count]; // favorites dictionary contains required info } - (uitableviewcell *)tableview:(uitableview *)tview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; } cell.textlabel.text = [nsstring stringwithformat:@"index: %d",indexpath.row]; homecoming cell; } this code works fine , display rows correctly first time only! after tableview loaded , if add together new item(s) in favorites or delete item(s), doesn't create difference tableview! want display available in favourites dictionary. seems cellforrowatindexpath doesn't invoked when viewappear again. there method tableview can utilize accomplish requirements?
i think you've missed phone call [tableview reloaddata];
iphone objective-c ios uitableview runtime
Comments
Post a Comment