我用 xib 自定义 cell 前面有个 button,写 cell 中监听 button,点击后发送通知到 tableView 修改数据,在通知方法中用 indexPathForSelectRow.row 拿到当前模型数据,但 indexPathForSelectRow.row 返回值一直为 0。
#pragma mark - 接受通知的方法
- (void)deleteBtnClick:(NSNotification *)note
{
NSLog(@"%ld" ,self.searchResult.indexPathForSelectedRow.row);
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这里你期望它是多少呢?是你点击 button 的那个 cell 吗? 你在这里取的是当前选中行,点击了那个 cell 里的一个 button,未必就选中了那个 cell。你可以试试在通知的 userInfo 里带着被点那一行的 row。或者其实不用搞这么麻烦的,用 block 来处理这样的事情会更容易一些。