在 .h 文件中:
@property (weak, nonatomic) IBOutlet UITableView *tableView;
在 .m 文件中:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"RememberedTableListCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [[listItems objectAtIndex:indexPath.row] objectForKey:@"word"];
return cell;
}
- (IBAction)resetList:(UIBarButtonItem *)sender {
UIAlertView *resetAlert = [[UIAlertView alloc] initWithTitle:@"Reset" message:@"Are you sure to reset the list?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[resetAlert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
// the user clicked Yes
if (buttonIndex == 1) {
// reset the list
//reload table data
NSLog(@"button yes is clicked");
for (NSMutableDictionary*l in listAll) {
[l setValue:@"0" forKey:@"remembered"];
}
[self.tableView reloadData];
//[[NSOperationQueue mainQueue]addOperationWithBlock:^{[self.tvRemembered reloadData];}];
//[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForSelectedRows] withRowAnimation:UITableViewRowAnimationNone];
NSLog(@"refreshing...");
}
}
如何刷新 UITableView 与 UIAlertView 委托(delegate) ?我试过
reloadData:
和 reloadRowsAtIndexPaths:
像上面一样。但他们没有帮助。任何帮助将不胜感激。
最佳答案
一段时间reloadData
不工作,所以你需要reloadData
有一些时间延迟,例如,
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
// the user clicked Yes
if (buttonIndex == 1) {
[self performSelector:@selector(reloadTableData) withObject:self afterDelay:0.20]; // set afterDelay as per your requirement.
}
}
在方法中
-(void)reloadTableData
{
[self.tableView reloadData];
}
了解更多信息
https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/reloadData
关于ios - 如何使用警报 View 刷新 uitableivew?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22755168/