我正在学习Objective-C,我想创建一个tableView。当我触摸一个表时,会显示一个警报视图。警报视图将显示一个名称,一个描述和两个可以输入新名称的textFields如何通过点击" Ok"更改名称和说明。 button.here是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
Coder *coder = _allCoder[indexPath.row];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Jack" message:@"Jack is a coder" preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder =@"name"; }];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"description";}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
UITextField *name = alertController.textFields.firstObject;
coder.name = name.text;
UITextField *desc = alertController.textFields.lastObject;
coder.desc = desc.text;
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}