ios - 根据通过 NSNotification 接收的索引从 TableView 中删除特定行

标签 ios objective-c uitableview

我有两个 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/

相关文章:

ios - 使用 xmpp 或任何其他框架在 ios 中使用 google 帐户构建聊天应用程序

ios - 我可以以编程方式检查 UITableViewCell 是什么样式吗?

tableview 单元格内的 ios 文本字段

ios - 在 Swift 2.0 中创建 CMSampleBuffer 的副本

ios - 为什么我的 iPhone 应用程序图标不起作用?

objective-c - NSTextContainer 排除路径 setter 无法识别?

ios - 如何在单元格获得自定义高度时自定义 UITableView 分隔符

ios - 旋转 CCSprite Cocos2D?

iOS应用程序在后台被杀死 - 如何调试?

ios - GMSMapViewDelegate 方法不起作用