gpt4 book ai didi

iphone - 关闭模态视图后,父 View 似乎已解除​​分配?

转载 作者:行者123 更新时间:2023-12-03 20:48:47 25 4
gpt4 key购买 nike

我正在编写一个 iPhone 应用程序。从导航堆栈中的 View Controller [称为 EditCreatorController] 开始,我将呈现一个自定义模态视图 Controller [称为 BMSStringPickerController]。我已经根据 Apple 指南创建了一个委托(delegate)协议(protocol)等,用于将数据传递回第一个 View 并使用该 View 来关闭模态视图。我什至从模态 Controller 获取了预期的数据,并且能够很好地忽略它。问题是,此时,我对原始 View Controller 执行的几乎任何操作都会导致调试器错误,例如

-[EditCreatorController PerformSelector:withObject:withObject:]:发送到已释放实例 0x3a647f0 的消息

-[EditCreatorController tableView:willSelectRowAtIndexPath:]:发送到已释放实例 0x3c12c40 的消息

换句话说,当模态视图显示时,原始 View Controller 似乎已经消失了。无论调用两个委托(delegate)回调中的哪一个,都是如此。

以下是父 Controller 中调用模态视图的代码:

- (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];

}
}

这是委托(delegate)回调:

 - (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 是我的 TableView 中标签的 IBOutlet),但它从未出现在那里,即使重新加载表。

有人有什么想法吗?

最佳答案

也许你在BMSStringPickerControllerdealloc中释放了delegate

关于iphone - 关闭模态视图后,父 View 似乎已解除​​分配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3224458/

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