我的問題是我從數據庫加載玩家到UITableView,我想將這些玩家存儲在Array中,但我提供了多個選擇。接下來我想將這些信息保存到數據庫。我已經完成了數據庫層,因此只需要有關如何將這多個選定球員存儲到數組的信息。對數組的多重選擇。
1
A
回答
0
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.cellSelected = [NSMutableArray array];
self.selectedItems = [NSMutableArray array];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Cell Initialisation here
if ([self.cellSelected containsObject:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//if you want only one cell to be selected use a local NSIndexPath property instead of array. and use the code below
//self.selectedIndexPath = indexPath;
//the below code will allow multiple selection
if ([self.cellSelected containsObject:indexPath])
{
[self.cellSelected removeObject:indexPath];
[self.selectedItems removeObject:[self.selectedItems indexOfObject:[self.dataArray objectAtIndex:indexPath.row]]];
}
else
{
[self.cellSelected addObject:indexPath];
[self.selectedItems addObject:[self.dataArray objectAtIndex:indexPath.row]];
}
[tableView reloadData];
}
你的數據數組存放數據庫中的數據(Whole players information)。 selectedItems數組包含所選玩家信息的詳細信息。 希望這會有所幫助:)
+0
[self.selectedItems removeObject:[self.selectedItems indexOfObject:[self.dataArray objectAtIndex: indexPath.row]]]; - 它給出了指針將NSUInteger發送給id_Nonnull類型的參數的incimpatible int – hds
相關問題
- 1. 多重選擇和v模型與對象數組
- 2. 如何篩選多重數組的多重數組?
- 3. 使用相同選擇器的多個組件,重新選擇
- 4. 選擇json對象數組
- 5. 選擇多對多的參數
- 6. 選擇多對多
- 7. SQL多重選擇和分組依據
- 8. SWT TableViewer無選擇的多重選擇
- 9. 基於另一個多重選擇的多重選擇
- 10. 從數組中選擇多選表格
- 11. 將選項對象數組添加到多個選擇
- 12. 多重選擇p:dataTable
- 13. 多重選擇IOS
- 14. 多重選擇DQL
- 15. UITableView多重選擇
- 16. mongoDB「多重」選擇
- 17. 多重選擇上
- 18. VueJS多重選擇
- 19. 多行選擇多維數組
- 20. bootstrap多重選擇,如何選擇整組後的所有組項目
- 21. 發送來自多重選擇的關聯數組
- 22. Chosen.js多重選擇選項
- 23. 選擇與對象數組不同的對象數組
- 24. 多重選擇字段 - 選擇=「選擇」多次
- 25. MaterializeCSS - 多重選擇 - 值在取消選擇後保持在數組中
- 26. jQuery的多維數組名選擇
- 27. jQuery UI的多重選擇
- 28. NSTableView的多重選擇
- 29. AlertDialog中的多重選擇
- 30. GtkCombo的多重選擇
請閱讀[如何問好問題](// stackoverflow.com/help/how-to-ask)並嘗試編輯您的問題。有了高質量的問題,您將會收到更快的答案。謝謝! – SmokeDispenser
可能的重複http://stackoverflow.com/questions/23727255/multiple-checkmark-when-row-selected-in-uitableview-ios –