我有一個具有UITableView的UIViewController,最多可以有7個單元格。我已經設置了選項cell.showsReorderControl = YES;
,用戶可以重新排列單元格。在創建單元格時,我還包含了cell.tag。iOS:在用戶重新排列單元格後查找cell.tag值
用戶重新排列單元格後,我想知道表格中單元格的排列方式。爲了做到這一點,我想我會設置標籤(不知道這是否是正確的方法)。
所以我的問題是在prepareForSegue,用戶重新洗牌單元格後,我想知道每個單元格的標籤值是多少?
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
[arrayTag replaceObjectAtIndex:sourceIndexPath.row withObject:[NSString stringWithFormat:@"%i",proposedDestinationIndexPath.row]];
[arrayTag replaceObjectAtIndex:proposedDestinationIndexPath.row withObject:[NSString stringWithFormat:@"%i",sourceIndexPath.row]];
return proposedDestinationIndexPath;
}
爲了驗證我做的NSLog
- (IBAction)doneButton:(id)sender
{
NSLog (@"Number of Objects in Array %i", arrayTag.count);
for (NSString *obj in arrayTag){
NSLog(@"From ArrayTag obj: %@", obj);
}
}
登錄不動,細胞:
2013-07-10 17:50:47.291 MyApp[1634:c07] Number of Objects in Array 7
2013-07-10 17:50:47.292 MyApp[1634:c07] From ArrayTag obj: 0
2013-07-10 17:50:47.292 MyApp[1634:c07] From ArrayTag obj: 1
2013-07-10 17:50:47.292 MyApp[1634:c07] From ArrayTag obj: 2
2013-07-10 17:50:47.292 MyApp[1634:c07] From ArrayTag obj: 3
2013-07-10 17:50:47.293 MyApp[1634:c07] From ArrayTag obj: 4
2013-07-10 17:50:47.293 MyApp[1634:c07] From ArrayTag obj: 5
2013-07-10 17:50:47.293 MyApp[1634:c07] From ArrayTag obj: 6
登陸後移動/洗牌細胞:
2013-07-10 17:51:55.329 MyApp[1634:c07] Number of Objects in Array 7
2013-07-10 17:51:55.330 MyApp[1634:c07] From ArrayTag obj: 4
2013-07-10 17:51:55.330 MyApp[1634:c07] From ArrayTag obj: 5
2013-07-10 17:51:55.330 MyApp[1634:c07] From ArrayTag obj: 5
2013-07-10 17:51:55.330 MyApp[1634:c07] From ArrayTag obj: 5
2013-07-10 17:51:55.331 MyApp[1634:c07] From ArrayTag obj: 6
2013-07-10 17:51:55.331 MyApp[1634:c07] From ArrayTag obj: 6
2013-07-10 17:51:55.331 MyApp[1634:c07] From ArrayTag obj: 4
我不確定問題是什麼,你有什麼試圖得到它? – micantox
我還沒有嘗試過任何東西。我不確定如何在用戶重新組合單元格後獲取每個單元格的標記值。 – user1107173