Siddharthan Asokan
Siddharthan Asokan

Reputation: 4441

UITableView - using reloadRowsAtIndexPath

I have aUITableView with delegate methods declared. ThenumberOfRows &numberOfSections are updated dynamically.

 (NSInteger)tableView:(UITableView *)tableView 
 numberOfRowsInSection:(NSInteger)section{}

 (NSInteger)numberOfSectionsInTableView:

Instead of using the [tableView reloadData], I would need to usereloadRowsAtIndexPath.

However I get a crash with invalid number of rows. How do I handle the dataSource changes? Lets says I have an array of count 10, and when I reload theUITableView usingUIRefreshControls by pulling, and the data from the server. From 10, if the count of array drops to 1, how will I handlereloadRowsAtIndexPath?

[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathForVisibleRows] withRowAnimation:UITableViewRowAnimationNone] 

There seems to be a crash when this is called. How would I handle change in data array's count?

Upvotes: 0

Views: 559

Answers (3)

Naresh Reddy M
Naresh Reddy M

Reputation: 1096

    //call begin and end updates while performing some hard core actions  on tableview
    [My_Table beginupdates];
    [My_Table reloadRowsAtIndexPaths:[My_Table indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
    [My_Table endupdates];
    hope it will helps you.

Upvotes: 1

VD Patel
VD Patel

Reputation: 286

you can try with this.

[tblMe beginUpdates];
[tblMe reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
[tblMe endUpdates];

Hope this may help !!!

Upvotes: 0

Samir
Samir

Reputation: 892

To reload specific cells of Tableview the method is reloadRowsAtIndexPaths: not reloadRowsAtIndexPath

    [self.tableview reloadRowsAtIndexPaths:[self.tableview indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];

However for reloadRowsAtIndexPaths to work properly datasource needs to be consistant. As Indexpaths are already loaded.

If you still use this method, You will get either arrayIndexOutofBound error or duplicate values in cells(depending on increase or decrease in datasource).

Upvotes: 1

Related Questions