Strange problem with [tableView reloadData]
Let have two mutable arrays, and let's have the following code:
- (void)viewDidLoad
{
NSMutableArray *A = [[NSMutableArray alloc] init];
NSMutableArray *B = [[NSMutableArray alloc] init];
// fill up A
// B remains empty
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ...
if (...)
{
// fill up the cell with datas of an object from A
}
else
{
// fill up the cell with datas of an object from B
}
//...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (...)
{
// remove an object from A and put it in B
}
else
{
// remove an object from B and put in A
}
[tableView reloadData];
}
If [tableView relo开发者_高级运维adData] is commented out (// [tableView reloadData]), than after the "click" the table will not be invalidated, as expected. And if the present cell scrolled off and scrolled in the screen again, "cellForRowAtIndexPath" is called and the cell "drawed" right according to which array from should its content be gained. But if [tableView reloadData] is active, while "cellForRowAtIndexPath" is not called at all (!) and the cell is deleted from the screen!
reaction: WHUT?
Can help me anybody how to invalidate the tableview on the fly (not by scrolling the cell off and in :))!
Thanks in advance!
You need to use the UITableView method -deleteRowsAtIndexPath... to perform the delete you're trying to achieve. Apple may not approve this UI paradigm though, as it violates the HIG.
Consider using the editing property, along with -commitEditingStyle... of the UITableViewDatasource for doing delete. Users will already be familiar with this usage of the table view, and it isn't at risk of being rejected by Apple.
It was my fault.. It's a very good experience, to me about this thing. The method:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [A count] + [B count];
}
only contained [A count] and [B count] not.. Actually with reloadData it wors propery. Anyhow it works due scroll-up - scroll-down while the numberOfRowsInSection is not queryed again.
Thank you all for your support!
精彩评论