小编Bou*_*Bou的帖子

使用deleteRowsAtIndexPaths后indexPath未更新

当用户想删除一个单元格时,我创建了一个更新我的UITableView的方法.

-(void)removeMoreFriendsRow:(NSNotification *)notification {
NSDictionary *d = [notification userInfo];
NSIndexPath *index = [d objectForKey:@"indexPath"];

[self.p_currentFriends removeObjectAtIndex:index.row];

[self.o_table deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationRight];
}
Run Code Online (Sandbox Code Playgroud)

p_currentFriends是一个NSMutableArray,它包含UITableView打印的所有对象.

当我使用它一次时,此方法可以正常工作,但是当我多次使用它时它会失败.

似乎每次调用deleteRowsAtIndexPaths时indexPath都保持不变.

例如, - 在第一次调用时,用户点击第二个单元格,indexPath = [0,1]并删除正确的单元格 - 在第二次调用时,用户点击第三个单元格并且indexPath = [0, 3]而不是[0,2]

/*希望我足够清楚:/*/

我发现使其工作的唯一方法是使用reloadData,但我希望在删除单元格时有动画.

有没有人有解决方案或提示?

objective-c uitableview

9
推荐指数
2
解决办法
3087
查看次数

在UISearchDisplayController上遇到僵尸问题

我在使用带有UITableView的UISearchDisplayController时有一个僵尸.

UISearchDisplayController(以及视图的其余部分)是通过界面构建​​器设置的(xcode 5上的故事板,仅使用ARC和iOS 7).

searchDisplayController由这两种方法使用

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    [self filterContentForSearchText:searchString scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    return YES;
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
    [self filterContentForSearchText:self.searchDisplayController.searchBar.text scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

仪器给了我这个信息

#   Event Type  ? RefCt RefCt   Timestamp   Responsible Library Responsible Caller
0   Malloc  +1  1   00:10.739.188   UIKit   -[UITableView setTableHeaderBackgroundColor:]
1   Retain  +1  2   00:10.739.214   UIKit   -[UIView(Internal) _addSubview:positioned:relativeTo:]
2   Retain  +1  3   00:10.739.234   UIKit   -[UISearchDisplayController _configureSearchBarForTableView]
3   Retain  +1  4   00:10.739.291   UIKit   -[UIView(Hierarchy) subviews]
4   Retain  +1 …
Run Code Online (Sandbox Code Playgroud)

storyboard nszombie uisearchdisplaycontroller automatic-ref-counting

7
推荐指数
1
解决办法
1457
查看次数