ios - Tableview reloadData and getting CGRect of new cell -


i have uitableview cards. every time want add new card after pushing draw button want moved center of view location in table should placed basic animation. have managed destination of new drawn card code:

cellrectintabledrawncard = [[self playercardstable] rectforrowatindexpath:drawncardindexpath]; cellinsuperviewdrawncard = [[self playercardstable]  convertrect:cellrectintabledrawncard toview:[[self playercardstable] superview]]; 

however, determine cellrectintabledrawncard need reload playercardstable reloaddata shows drawn card already. fraction of second because place new card in table animation fires after reloaddata. doing reload after animation not option, because don't have drawncardindexpath then.

is there way can rect without reloading tableview? or else, there way can hide new cell after reloaddata , show after animation done?

thanks!

you want insert row , populate individually , not complete table reload.

the code snippet shows button uses insertrowsatindexpaths:indexpatharray add new row gives cell rect animation stuff. when you're done animation use reloadrowsatindexpaths populate cell value (show you're card i'd guess).

use bool decide in cellforrowatindexpath when should display new card (basically after call reloadrowsatindexpaths).

- (ibaction)butaddcardtohandaction:(id)sender {     // add blank record array     nsstring *strcard = @"new card";     _showcard = no;     [_arrayhandcards addobject:strcard];      // create index path want add card     nsindexpath *indexpath = [nsindexpath indexpathforrow:(_arrayhandcards.count - 1) insection:0];     nsarray *indexpatharray = [nsarray arraywithobjects:indexpath,nil];      // update table     [self.tableview beginupdates];     [self.tableview insertrowsatindexpaths:indexpatharray withrowanimation:uitableviewrowanimationnone];     [self.tableview endupdates];     // ok - got blank record in table, cell rect.     cgrect cellrectintabledrawncard = [[self tableview] rectforrowatindexpath:indexpath];     nslog(@"my new rect has y position : %f",cellrectintabledrawncard.origin.y);      //do animation need , when finished populate selected cell       _showcard = yes;     [self.tableview reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationnone]; } 

code control whats displayed in cell:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellidentifier = @"cell";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     }     // set cell , use boolean decide show     nsstring *strtodisplayincell;     if (!_showcard)     {         strtodisplayincell = @"";     }     else     {         nsstring *strtodisplayincell = [_arrayhandcards objectatindex:indexpath.row];         cell.textlabel.font = [uifont fontwithname:@"helvetica" size:15];         cell.textlabel.text = strtodisplayincell;     }     return cell; } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -