【发布时间】:2014-03-31 06:50:52
【问题描述】:
在.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...");
}
}
如何使用 UIAlertView 委托 刷新 UITableView?我已经尝试过reloadData: 和reloadRowsAtIndexPaths:,就像上面一样。但他们没有帮助。任何帮助将不胜感激。
【问题讨论】:
-
您是否记录了 buttonIndex one 的任何语句?
-
是的,没关系。
-
能否提供
alertView的代码? -
放置断点可能是您的 AlertView 委托未被调用。
-
[[NSOperationQueue mainQueue]addOperationWithBlock:^{self.table reloadData}];尝试在主线程中刷新表格视图
标签: ios objective-c uitableview