我有两个 View Controller 。
第一个 View Controller 有一个 TableView 。 当用户单击第一个 View Controller 的 TableView 中的单元格时,他将被引导到第二个 View Controller 。
当用户再次返回到第一个 View Controller 时,他之前点击的表格 View 单元格必须从表格 View 中删除
以下是我的代码
-(void)reloadOnAction:(NSNotification *)notis{
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *dict = notis.userInfo;
int index_Id = [[dict objectForKey:@"post_notification"] intValue];
if ([_statNameArray count] != 0){
[_statNameArray removeObjectAtIndex:index_Id];
}
[_tblView reloadData];
});}
index_Id 包含必须删除的元素。 虽然我在更改数组后重新加载了 TableView ,但这些更改并未反射(reflect)在用户界面中。我该如何解决这个问题?
以下是我的 numberOfRowsInSection 方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.statNameArray count];
}
最佳答案
您可以将必须删除的行存储在数组中,并在 viewWillAppear 方法中删除这些行。
应该是这样的:
@interface TableViewController ()
@property (nonatomic) NSInteger selectedIndex;
@property (nonatomic, strong) NSMutableArray *statNameArray;
@end
@implementation TableViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([self.statNameArray count] != 0){
[self.statNameArray removeObjectAtIndex:self.selectedIndex];
[self.tableView reloadData];
}
}
- (void)reloadOnAction:(NSNotification *)notis{
NSDictionary *dict = notis.userInfo;
self.selectedIndex = [[dict objectForKey:@"post_notification"] intValue];
}
关于ios - 根据通过 NSNotification 接收的索引从 TableView 中删除特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37161938/