ios - insertRowsAtIndexPaths Not Working, Crashing With Object At Index Out Of Bounds? -



ios - insertRowsAtIndexPaths Not Working, Crashing With Object At Index Out Of Bounds? -

searched , searched.. can't find reply :|

i'm pretty sure i'm using insertrowsatindexpaths right... here's code, along error i'm receiving...

first, receive response server comments want insert dynamically empty section within static uitableviewcontroller's tableview.

this happens when receive response server...

i count number of comments returned, , generate array of index paths empty section, section 1.

i run standard way of inserting rows encapsulation between begin/end updates.

great..

now, here's tableview's related code.

everything runs fine 1 time response server, insert assume works...

however, when start scrolling downwards view, scroll right before first comment show, crash next error, , nil pointing me in direction be

it's strangest thing... , nslog right before crash can see it's attempting cell index path of section 1 row 0, first comment should be... what's going on??

update here value of self.recentcomments prior indexpaths array beingness created.

update 2 here's value of self.recentcomments in cellforrowatindexpath right before crash.

this strange. suggest [self.tableview reloaddata] instead insertrowsatindexpath.

you 1 time response server :

-(void)loadrecentcommentsresponse:(nsdictionary *)data { int status = [[[data objectforkey:@"meta"] onjectforkey:@"status"] intvalue]; if(status == status_ok){ self.recentcomments = [[data objectforkey:@"response"] objectforkeys:@"comments"]; [self.tableview reloaddata]; } }

since not reloading uitableview unable recognize number of row displayed in numberofrowsinsection method.

update :

-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (!cell) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } //do stuff here homecoming cell; }

you missed if(!cell) block. used if cell not initialized, initialized. whenever scroll uitableview `cellforrowatindexpath method called everytime.

thanks.

ios objective-c xcode cocoa-touch cocoa

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -