我有一个从 SQLite 数据库中提取信息并填充 TableView 中的单元格的应用程序。但是,我希望用户能够单击一个单元格,然后能够通过 AlertView 编辑该单元格中的内容。以下是我的代码的一部分:
//Set up cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [resultSet objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
CustomCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Question" message:@"Please enter a new question" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
av.alertViewStyle = UIAlertViewStylePlainTextInput;
txtNewQuestion = [av textFieldAtIndex:0];
txtNewQuestion.clearButtonMode = UITextFieldViewModeWhileEditing;
av.delegate = self;
[txtNewQuestion setPlaceholder:@"new Question"];
[av show];
[self.txtNewQuestion becomeFirstResponder];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
CustomCell *cell;
enteredQuestion = txtNewQuestion.text;
cell.customLabel.text = enteredQuestion;
NSLog(@"%@", enteredQuestion);
NSLog(@"%@", cell.customLabel.text);
}
[self.tableView reloadData];
}
任何帮助将不胜感激。谢谢。