我正在编写一个 iPhone 应用程序。从导航堆栈中的视图控制器 [称为 EditCreatorController] 开始,我将展示一个自定义模式视图控制器 [称为 BMSStringPickerController]。我根据 Apple 指南创建了一个委托协议等,用于将数据传递回第一个视图并使用该视图来关闭模式视图。我什至从模态控制器中获取了预期的数据,并且能够很好地忽略它。问题是,在这一点上,我对原始视图控制器执行的几乎所有操作都会导致调试器错误,例如
-[EditCreatorController performSelector:withObject:withObject:]:消息发送到释放的实例 0x3a647f0
或者
-[EditCreatorController tableView:willSelectRowAtIndexPath:]: 消息发送到释放实例 0x3c12c40
换句话说,看起来原来的视图控制器在模态视图显示时已经消失了。无论调用两个委托回调中的哪一个都是如此。
这是调用模态视图的父控制器的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1) { // selection on creator type row
// create a string picker to choose new creator type from list
BMSStringPickerController *picker = [[BMSStringPickerController alloc] initWithNibName:@"BMSStringPickerController" bundle:nil];
picker.delegate = self;
picker.stringChoices = [NSArray arrayWithObjects:@"composer", @"lyricist", @"arranger", @"original artist", @"other", nil];
picker.currentChoice = creator.type;
picker.title = @"Creator Type";
// wrap it in a nav controller so we can get tile bar etc. (from VC prog guide p. 93)
UINavigationController *newNavigationController = [[UINavigationController alloc]
initWithRootViewController:picker];
[self.navigationController presentModalViewController:newNavigationController animated:YES];
[newNavigationController release];
[picker release];
}
}
这是委托回调:
- (void)stringPickerController:(BMSStringPickerController *)picker didPickString:(NSString *)string {
NSLog(@"received string back: %@", string);
typeLabel.text = string; // only change the label for now; object only changes if done button pressed
[self.tableView reloadData];
[self dismissModalViewControllerAnimated:YES];
}
- (void)stringPickerControllerDidCancel:(BMSStringPickerController *)picker {
NSLog(@"picker cancelled");
[self dismissModalViewControllerAnimated:YES];
}
另一个奇怪的事情(也许是一个线索)是,虽然我得到了“收到的字符串” NSLog 消息,并将其分配给 typeLabel.text (typeLabel 是我表视图中标签的 IBOutlet),但它从未出现在那里,即使有表重新加载。
有人有什么想法吗?