2016-02-29 26 views
1

我的問題是我從數據庫加載玩家到UITableView,我想將這些玩家存儲在Array中,但我提供了多個選擇。接下來我想將這些信息保存到數據庫。我已經完成了數據庫層,因此只需要有關如何將這多個選定球員存儲到數組的信息。對數組的多重選擇。

+0

請閱讀[如何問好問題](// stackoverflow.com/help/how-to-ask)並嘗試編輯您的問題。有了高質量的問題,您將會收到更快的答案。謝謝! – SmokeDispenser

+0

可能的重複http://stackoverflow.com/questions/23727255/multiple-checkmark-when-row-selected-in-uitableview-ios –

回答

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