gpt4 book ai didi

iphone - 加载 UIView 到 navigationalStack 不传递字符串到新 View

转载 作者:行者123 更新时间:2023-11-29 13:41:11 25 4
gpt4 key购买 nike

我正在尝试将一个字符串传递到我的导航 Controller 的详细 View 取决于所选的 tableviewcell 将取决于传递的值。

由于某种原因,当我返回到表格 View 并选择下一个单元格(或任何其他单元格,包括第一个单元格)时,选择的第一个单元格传递了正确的数据,它没有传递任何内容...

这是我的代码。

主视图:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Sets the back button for the new view that loads (this overrides the usual parentview name with "Back")
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];

if (!self.detailViewController) {
self.detailViewController = [[ICDDetailViewController alloc] initWithNibName:@"ICDDetailViewController" bundle:nil];

if (indexPath.section == 0) {
_detailViewController.parentViewSelectedIndexPath = @"one";
}
if (indexPath.section == 1) {
_detailViewController.parentViewSelectedIndexPath = @"two";
}
if (indexPath.section == 2) {
_detailViewController.parentViewSelectedIndexPath = @"three";
}
}
[self.navigationController pushViewController:self.detailViewController animated:YES];
}

然后进入详细 View

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.



NSLog(@"%@", parentViewSelectedIndexPath);


}

这是输出,它显示我选择了第一个 tableviewcell 然后之后的所有内容都不会被读取。

2012-02-01 09:34:23.797 Diagram Test[1154:207] one

最佳答案

在你的第一个表类中,你有一行用于如果 detailView 不存在,则创建它。

很有可能,detailView 仍然由您的 tableView 类加载和保留。如果您想根据您在表格中触摸的内容重新加载整个 detailView,请删除 if(!detailView) 行,而只需运行 self.detailView = [[yaddayadda alloc...

-viewDidLoad 方法只触发一次。

PS:你还需要从 if 语句中取出 if (section ==) 逻辑。

改成这样:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Sets the back button for the new view that loads (this overrides the usual parentview name with "Back")
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];


self.detailViewController = [[ICDDetailViewController alloc] initWithNibName:@"ICDDetailViewController" bundle:nil];

if (indexPath.section == 0) {
_detailViewController.parentViewSelectedIndexPath = @"one";
}
if (indexPath.section == 1) {
_detailViewController.parentViewSelectedIndexPath = @"two";
}
if (indexPath.section == 2) {
_detailViewController.parentViewSelectedIndexPath = @"three";
}

[self.navigationController pushViewController:self.detailViewController animated:YES];
}

关于iphone - 加载 UIView 到 navigationalStack 不传递字符串到新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9086662/

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