我设法创建了我的uitableview,其中填充了sql测验数据。现在我正在尝试创建一个select deselect方法。在单元格的勾选标记后,我想按下开始按钮和选中的选项,我想出现一个新的游戏屏幕,其中包含来自所选类别的混合测验问题。这可行吗?
这是一些代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
if ([self isRowSelectedOnTableView:tableView atIndexPath:indexPath]) {
[self.selectedCells removeObject:indexPath];
cell.accessoryType =UITableViewCellAccessoryNone;
}else{
[self.selectedCells addObject:indexPath];
cell.accessoryType =UITableViewCellAccessoryCheckmark;
}
NSNumber * selectedRow = [NSNumber numberWithInteger:indexPath.row];
NSLog(@"%@", selectedRow);
startButton.tag = selectedRow?10:0;
}
这是我尝试按钮操作
- (IBAction)startAction:(id)sender
{
if([sender tag] == 10){
PlayViewController * controller = [[PlayViewController alloc] initWithNibName:@"PlayViewController" bundle:nil];
[self presentViewController:controller animated:YES completion:nil];
}
标签只是尝试按钮。我真正想要的是读取所选的行号并用它来为播放视图控制器创建sql语句。可能吗? 提前谢谢。
答案 0 :(得分:0)
我不完全明白你要做什么。
但是在didSelectRowAtIndexPath中,您不需要再次定义单元格。您有indexPath.row值,该值指示选择表的哪一行。您可以存储该值以供以后使用。您还可以存储所选记录。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedRow = indexPath.row; // store the table row number
// or
selectedRecord=[fullTableArray objectAtIndex:indexPath.row]; // store the value