[英]How to store objects at two different indexes of one NSArray to one index of another NSArray
[英]How do I to Delete objects in different indexes of one NSArray? IOS
好吧,伙計們。
當我嘗試刪除一個NSMutableArray
不同索引處的對象時,我在這里遇到問題。 我知道如何使用方法[_tableFavoritos indexPathsForSelectedRows]
初始化一個NSIndexPath
NSArray
,但是我不知道如何從該NSArray
創建一個NSIndexSet
。
我想用這種方法
[arrayFavoritos removeObjectsAtIndexes : (here my NSIndexSet) ];
為了解決這個。
或者,如果有人知道另一種方式,請歡迎。
謝謝...
NSArray *indexesArray = [[NSArray alloc]initWithArray:[_tableFavoritos indexPathsForSelectedRows]];
[arrayFavoritos removeObjectsAtIndexes:];
[_tableFavoritos deleteRowsAtIndexPaths:[_tableFavoritos indexPathsForSelectedRows] withRowAnimation:UITableViewRowAnimationFade];
[_tableFavoritos reloadData];
這應該為您工作:
NSArray *indexesArray = [[NSArray alloc]initWithArray:[_tableFavoritos indexPathsForSelectedRows]];
NSMutableIndexSet *indexSet = [NSMutableIndexSet new];
[indexesArray enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
[indexSet addIndex:indexPath.row];
}];
[arrayFavoritos removeObjectsAtIndexes:indexSet];
[_tableFavoritos deleteRowsAtIndexPaths:[_tableFavoritos indexPathsForSelectedRows] withRowAnimation:UITableViewRowAnimationFade];
[_tableFavoritos reloadData];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.