IOS application crashes when trying to insert new row in UITableView?

The numberOfRowsInSection method should return the correct number of rows whenever you make any change to the data source of table view For example if the total number of rows in the table is 5 and if you are going to add one more row, then the numberOfRowsInSection method should return 6 Its easily achieved by having the data in an array or dictionary If you want to add or delete rows just update the array or dictionary. And just return array count or dictionary count from numberOfRowsInSection method.

The numberOfRowsInSection method should return the correct number of rows whenever you make any change to the data source of table view. For example if the total number of rows in the table is 5 and if you are going to add one more row, then the numberOfRowsInSection method should return 6. Its easily achieved by having the data in an array or dictionary.

If you want to add or delete rows just update the array or dictionary. And just return array count or dictionary count from numberOfRowsInSection method.

I have updated the post with further information. – Wstr Aug 28 at 15:03.

You need to update the number returned inside your -tableView:numberOfRowsInSection: after inserting or deleting rows.

The number does update, but the app crashes immediately afterwards. – Wstr Aug 28 at 15:23 Where does it update? It should update between self.

TableView beginUpdates; and self. TableView endUpdates; – fichek Aug 28 at 15:28 All I can see, is that in between self. Tableview beginUpdates and self.

Tableview endUpdates the - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section method gets called, returning an incremented number from the one before it. So if I launch my app and there's two rows in the table view, it'll return 3 when receiving a push notification. I've updated my post with additional info.

– Wstr Aug 28 at 15:32 NSString *path = LoadPlist alloc init; data = NSMutableDictionary alloc initWithContentsOfFile:path; return data count; You are allocating a new instance to data every time you need a cell count? That's very bad and will leak a lot of data. If data is instance variable, third line alone would work.

– fichek Aug 28 at 15:40 That was one of my desperate attempts of solving the problem. I've removed the superfluous code, but the problem persists... – Wstr Aug 28 at 15:44.

I think your problem is with the number of rows method in the datasource just do one thing define int noOfRows in your . Assign your table view array count with the noOfRows. Then return noOfRows from table views numberOfRowsInSection method.

Add 1 to noOfRows if you insert row in the table. You will not get this exception . Update your array as per your requirement.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions