table reloadData无法正常工作 [英] table reloadData not working
本文介绍了table reloadData无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码从tableview中删除一行以及db,
该行一次从db中删除但是它没有从tableview中删除,直到我退回并且chk aggain,我想要当我delet行tableview应该rload数据...
任何想法?
i am using following code to delet a row from tableview as well from db , the row is delted from the db at once but its not delted from the tableview till i back back and th chk aggain ,i want when i delet the row tableview should rload the data... any idea ?
-(void) tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.table beginUpdates];
if (editingStyle == UITableViewCellEditingStyleDelete)
{
Hadits *delHadit = [self.allBookMarks objectAtIndex:indexPath.row];
dbAccess *dbmethods = [[dbAccess alloc] init];
NSInteger delHaditid = delHadit.haditid;
[dbmethods deleteBookMark:delHaditid];
[dbmethods release];
}
[self.table reloadData];//its not working reload data...
[table endUpdates];
}
推荐答案
包括这一行,
[self.allBookMarks removeObjectAtIndex:indexPath.row];
编辑:
问题不在于reloadData,问题在于您没有更新数据源(self.allBookMarks)。将值更新为self.allBookMarks然后重新加载表格。
The problem is not with reloadData, the problem is that you are not updating your datasource (self.allBookMarks). Update the values into self.allBookMarks then reload the table.
编辑代码
-(void) tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.table beginUpdates];
if (editingStyle == UITableViewCellEditingStyleDelete)
{
Hadits *delHadit = [self.allBookMarks objectAtIndex:indexPath.row];
dbAccess *dbmethods = [[dbAccess alloc] init];
NSInteger delHaditid = delHadit.haditid;
[dbmethods deleteBookMark:delHaditid];
self.allBookMarks = [dbMethods getAllBookMarks];
[dbmethods release];
}
[self.table reloadData];//its not working reload data...
[table endUpdates];
}
这篇关于table reloadData无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文