iOS/iPhone didSelectRowAtIndexPath self.navigationController PushViewController 不起作用
我肯定要失去理智了。我已经编写了我认为相当标准的用法的代码 这里的 didSelectRowAtIndexPath:
方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
if (row == 0){
BuildingDescriptionViewController *buildingDescriptionViewController = [[BuildingDescriptionViewController alloc] initWithNibName:@"BuildingDescriptionViewController" bundle:[NSBundle mainBundle]];
NSLog(@"self.navigationController0 is %@", self.navigationController ? @"not nil" : @"nil");
[self.navigationController pushViewController:buildingDescriptionViewController animated:YES];
[buildingDescriptionViewController release];
}
else if (row == 1){
PostCommentViewController *buildingCommentViewController = [[PostCommentViewController alloc] init];
NSLog(@"self.navigationController1 is %@", self.navigationController ? @"not nil" : @"nil");
[self.navigationController pushViewController:buildingCommentViewController animated:YES];
[buildingCommentViewController release];
}
}
NSLog 通知 navigationController 不为 nil,但没有其他情况发生。 viewController 都不会出现。事实上,只是发生了 NSLog。我缺少一些深奥的用法吗?我也尝试过 [selfpresentModalViewController:buildingDescriptionViewControlleranimated:YES];但什么也没发生。我确实需要一些帮助。 谢谢。
更新: 根据下面 Saiesh 建议的输出
2011-06-27 18:02:56.370 某事[16331:207]buildingdescriptionviewcontrollerinit 2011-06-27 18:02:56.370 某事[16331:207] ViewControllers 在推送之前:( “建筑配置文件视图控制器:0x7e89680” )
2011-06-27 18:02:56.370 某事[16331:207] 推送后的 ViewControllers:( “BuildingProfileViewController:0x7e89680>”, “建筑描述视图控制器:0x7e73d30” )
2011-06-27 18:03:15.843 某事[16331:207]buildingdescriptionviewcontrollerinit
2011-06-27 18:03:15.844 某事[16331:207] ViewControllers 在推送之前:( “BuildingProfileViewController:0x7e89680”, “建筑描述视图控制器:0x7e73d30” )
2011-06-27 18:03:15.844 某事[16331:207] 推送后的 ViewControllers:( “建筑配置文件视图控制器:0x7e89680” “建筑描述视图控制器:0x7e73d30” “建筑描述视图控制器:0xcc2c8e0” )
I am surely losing my mind. I have coded what I assume to be a fairly standard usage of thedidSelectRowAtIndexPath:
method here:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
if (row == 0){
BuildingDescriptionViewController *buildingDescriptionViewController = [[BuildingDescriptionViewController alloc] initWithNibName:@"BuildingDescriptionViewController" bundle:[NSBundle mainBundle]];
NSLog(@"self.navigationController0 is %@", self.navigationController ? @"not nil" : @"nil");
[self.navigationController pushViewController:buildingDescriptionViewController animated:YES];
[buildingDescriptionViewController release];
}
else if (row == 1){
PostCommentViewController *buildingCommentViewController = [[PostCommentViewController alloc] init];
NSLog(@"self.navigationController1 is %@", self.navigationController ? @"not nil" : @"nil");
[self.navigationController pushViewController:buildingCommentViewController animated:YES];
[buildingCommentViewController release];
}
}
The NSLog informs that the navigationController is NOT nil, but nothing else happens. Neither viewController appears. In fact, just the NSLog occurs. Is there some esoteric usage I am missing? I have also tried [self presentModalViewController:buildingDescriptionViewController animated:YES]; and nothing happened. I could really use some assistance.
Thanks.
UPDATE:
Output per Sailesh's suggestion below
2011-06-27 18:02:56.370 something[16331:207] buildingdecriptionviewcontrollerinit
2011-06-27 18:02:56.370 something[16331:207] ViewControllers before pushing: (
"BuildingProfileViewController: 0x7e89680"
)2011-06-27 18:02:56.370 something[16331:207] ViewControllers after pushing: (
"BuildingProfileViewController: 0x7e89680>",
"BuildingDescriptionViewController: 0x7e73d30"
)2011-06-27 18:03:15.843 something[16331:207] buildingdecriptionviewcontrollerinit
2011-06-27 18:03:15.844 something[16331:207] ViewControllers before pushing: (
"BuildingProfileViewController: 0x7e89680",
"BuildingDescriptionViewController: 0x7e73d30"
)2011-06-27 18:03:15.844 something[16331:207] ViewControllers after pushing: (
"BuildingProfileViewController: 0x7e89680"
"BuildingDescriptionViewController: 0x7e73d30"
"BuildingDescriptionViewController: 0xcc2c8e0"
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查视图控制器是否真的被推入导航堆栈。
要进行检查,请执行以下操作:
控制台中的输出将是 viewController 的一些地址,但您至少会知道推送 viewController 之前和之后导航堆栈中的 viewController 的数量。我想,如果它们被推动,那么问题一定出在代码的其他部分。
请回复输出。
Check if the view controller is really being pushed into the navigation stack.
To check, do this:
The output in the console will be some adresses of the viewControllers, but you will at least know the number of viewControllers in the navigation stack before and after pushing viewController. If they ARE getting pushed, then the problem must be in some other part of your code, I suppose.
Please reply with the output.
我终于找到了问题所在。我对 self.navigationController 不是 NIL 感到困惑。问题是 tableView 已被添加为子视图。我通过将其 viewController 推送到导航堆栈来修复它。感谢所有回复的人。
I finally found the problem. I was confused by the fact that the self.navigationController wasn't NIL. The issue was that the tableView had been added as a subview. I fixed it by pushing its viewController onto the navigation stack. Thanks to everyone that replied.
我刚刚通过调用任何视图方法或属性解决了我的问题。
过去三天我也遇到了同样的问题。虽然
viewController
正在添加,但只有RootViewController
出现,而不是YouTubeEmbedPlayer
。2011-06-27 19:53:17.677 [1263:207]
ViewControllers
推送前:( "", "", "", "" ) 2011-06-27 19:53:22.496 [ 1263:207] 推送前的 ViewControllers:(“”、“”、“”、“”、“”)I just resolved my issue by calling any view method or property.
I also had the same issue for the last 3 days. Although the
viewController
is getting added but onlyRootViewController
is coming up but notYouTubeEmbedPlayer
.2011-06-27 19:53:17.677 [1263:207]
ViewControllers
before pushing: ( "", "", "", "" ) 2011-06-27 19:53:22.496 [1263:207] ViewControllers before pushing: ( "", "", "", "", "" )