作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将一个字符串传递到我的导航 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/
我正在尝试将一个字符串传递到我的导航 Controller 的详细 View 取决于所选的 tableviewcell 将取决于传递的值。 由于某种原因,当我返回到表格 View 并选择下一个单元格(
我是一名优秀的程序员,十分优秀!