【问题标题】:Update datasource and reload data on UITableView not reflecting updated datasource更新数据源并在 UITableView 上重新加载数据不反映更新的数据源
【发布时间】:2016-01-12 14:12:19
【问题描述】:

这是我的一段代码:

NSMutableDictionary *newDict = [[NSMutableDictionary alloc] init];
NSDictionary oldDict = (NSDictionary )[dataArray objectAtIndex:0];
[newDict addEntriesFromDictionary:oldDict];
[newDict setObject:@"Don" forKey:@"Name"];
[dataArray replaceObjectAtIndex:0 withObject:newDict];
[self.tblview reloadData];

我必须重新加载我的tableview。但是tableview没有重新加载。如何纠正它。

【问题讨论】:

  • 显示你的cellForRow
  • - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {if(tableView == self.tblviewProject) {self.tblviewProject.hidden = YES; NSString *pname = [[self.projectArray objectAtIndex:indexPath.row] objectForKey:@"name"]; NSMutableDictionary *newDic = [[NSMutableDictionary alloc] init]; NSDictionary *rowchange = (NSDictionary *) [self.dataArray objectAtIndex:[self.projIndexPath intValue]]; [newDic addEntriesFromDictionary:rowchange]; [newDic setObject:pname forKey:project]; [self.tblview beginUpdates];
  • [self.dataArray replaceObjectAtIndex:[self.projIndexPath intValue] withObject:newDic]; [self.tblview reloadData]; [self.tblview endUpdates]; }}
  • 这是我的行单元格...现在我添加了 begin 和 endupdates 但它不起作用。
  • @RBH 不要将代码放入 cmets。将您的代码放入您的问题中。

标签: ios objective-c uitableview nsarray


【解决方案1】:

尝试开始和结束更新,因为您实际上并没有更改源数组。

而不是[self.tblview reloadData]调用:

[self.tblview beginUpdates];
[self.tblview endUpdates];

或者,重新加载部分也应该在这种情况下工作。

【讨论】:

  • - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {if(tableView == self.tblviewProject) {self.tblviewProject.hidden = YES; NSString *pname = [[self.projectArray objectAtIndex:indexPath.row] objectForKey:@"name"]; NSMutableDictionary *newDic = [[NSMutableDictionary alloc] init]; NSDictionary *rowchange = (NSDictionary *) [self.dataArray objectAtIndex:[self.projIndexPath intValue]]; [newDic addEntriesFromDictionary:rowchange]; [newDic setObject:pname forKey:project]; [self.tblview beginUpdates];
  • [self.dataArray replaceObjectAtIndex:[self.projIndexPath intValue] withObject:newDic]; [self.tblview reloadData]; [self.tblview endUpdates]; }} 但现在它对我不起作用...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-08
  • 2018-04-04
  • 2020-07-16
  • 1970-01-01
  • 1970-01-01
  • 2019-12-01
  • 1970-01-01
相关资源
最近更新 更多