ios - 如何使用警报 View 刷新 uitableivew?

标签 ios objective-c uitableview

在 .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/

相关文章:

ios - 无法让 Core Bluetooth 在 Swift iOS playground 中工作

ios - 子类化 iOS 控件 - 代码与 Storyboard

ios - 文本从下到上对齐 iOS SDK

ios - 调整 View 的高度以包含 TableView 的行数

objective-c - 如何在 iOS 分组 UITableView 中获取矩形 UITableViewCells

ios - 如果没有显示广告,则替换 View - AdMob

ios - 防止通话状态栏影响 View

objective-c - 是否有可以在 Windows 上运行的 Mac 模拟器或 Objective-C 环境?

iphone - 设置 UITableViewCell 的动态高度,其中仅包含图像(可变高度)

ios - 使用 Obejctive C 在 tableview 单元格中搜索特定值时如何获取所有数组值?