gpt4 book ai didi

ios - 将文本从 UIAlertView 文本字段传递到自定义单元格标签

转载 作者:行者123 更新时间:2023-11-29 02:53:58 24 4
gpt4 key购买 nike

我有一个应用程序可以从 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];

}

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

我会改用 didSelectRowAtIndexPath,有时我喜欢使用标签:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Question" message:@"Please enter a new question" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
av.alertViewStyle = UIAlertViewStylePlainTextInput;
av.delegate = self;
av.tag = [indexPath row];
[av show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
[resultSet replaceObjectAtIndex:alertView.tag withObject:[alertView textFieldAtIndex:0].text];
[table reloadData];
}
}

关于ios - 将文本从 UIAlertView 文本字段传递到自定义单元格标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24142285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com