将UIViewController推送到NavigationController实际上并不推送视图 [英] Pushing UIViewController to NavigationController does not actually push the view

查看:87
本文介绍了将UIViewController推送到NavigationController实际上并不推送视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表视图控制器(和委托)中有这个代码:

   - (void)tableView:(UITableView * )tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailStatus * detailViewController = [[DetailStatus alloc] initWithNibName:@DetailStatusbundle:nil status:[mStatuses objectAtIndex:indexPath.row]];
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
NSLog(@退出didselectrow);

}

在我的DetailStatus类中:

   - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil status:(NSDictionary *)pStatus {
NSLog( @我被称为%d,[pStatus objectForKey:@id]);
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if(self){
// some stuff
}
return self;
}

有趣的是,我的DetailStatus实际上是在控制台窗口中初始化的,它甚至输出我被称为000001但奇怪的是视图没有被推到表格视图...



我检查了笔尖名称,没关系。我检查了DetailStatus标题文件,它看起来没问题(像这样):

  @interface DetailStatus:UIViewController {

所以有人都知道为什么视图没有被推到窗口,即使我已经初始化并推动了它? / p>

更新:我尝试将一些调试消息记录到DetailStatus中的viewDidLoad,看起来即使该类被实例化也没有加载视图......我想知道为什么。



UPDATE2:我觉得这可能是我的导航控制器组织错了..我有以下内容:

 登录页面 - > customtabbar  - >第一个表视图 - > DetailStatus 
- >第二个表视图 - > DetailStatus

我想我只在该层次结构中维护一个导航控制器。我从未创建过其他导航控制器。我只推动一个又一个的观点。



谢谢大家的答案!我会尽快给出赏金,我会让其他人在赏金到期前先投票。

解决方案

看完之后,情节似乎和我一样。我第一次面对Tab +导航时遇到的问题。



我确定你的Tab +有问题基于导航的应用。
虽然它显示Tab以及导航无法导航基本流程。并且用这么少的代码来解决你的问题非常困难。



除此之外,我还有一个替代解决方案:



一旦你有一个标签栏一个XIB,最简单的方法是将UINavigationController对象从Library窗口(看起来像金色背景上的左侧导航栏按钮)拖动到标签栏的树视图中(仅文本视图,而不是GUI )。将它放在标签栏下,然后拖动标签栏控制器下的现有视图控制器而不是标签栏。



当你去查看该标签时,你应该看到它顶部的导航栏...如果你从另一个xib加载导航控制器,你将修改标签栏xib中的导航栏。



否则你可以在下面跟随最佳网址:



http://books.google.co.in/books?id=2yYlm_2ktFYC& ; PG = PA179&安培; LPG = PA179&安培; DQ =导航+有+ + +标签基于+应用+ iphoneSDK&安培;源= BL&安培; OTS = nf2YYjX5Am&安培; SIG = COpHj9wOtsDCh QBglpsljSTsElw& hl = en& ei = 3ZoFTeGSOI_tsgbc_Iz6CQ& sa = X& oi = book_result& ct = result& resnum = 6& ved = 0CDAQ6AEwBQ #v = onepage& q& f = false



http://www.youtube.com/watch?v=LBnPfAtswgw



希望这一定能解决您的问题。


I have this code in my table view controller (and delegate):

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailStatus *detailViewController = [[DetailStatus alloc] initWithNibName:@"DetailStatus" bundle:nil status:[mStatuses objectAtIndex:indexPath.row]];
    [[self navigationController] pushViewController:detailViewController animated:YES];
    [detailViewController release];     
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
    NSLog(@"exiting didselectrow");

}

And in my DetailStatus class:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil status:(NSDictionary *)pStatus {
    NSLog(@"I am being called %d", [pStatus objectForKey:@"id"]);
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {
        // some stuff
    }
    return self;
}

The funny thing is, my DetailStatus is actually being initialised, in the console window, it even outputs "I am being called 000001" but strangely the view is not being pushed to the table view...

I've checked the nib name, and it's ok. I checked the DetailStatus heading file, it looks ok (like this):

@interface DetailStatus : UIViewController {

So does anyone know why the view is not being pushed to the window even if I've initialised it and pushed it?

UPDATE: I tried logging some debugging messages to viewDidLoad in DetailStatus, and it seems like the view is not loaded even though the class was instantiated... I wonder why.

UPDATE2: I have a feeling that this might be my navigation controller organisation that's wrong.. I have this following:

Login page -> customtabbar -> First table view -> DetailStatus
                           -> Second table view -> DetailStatus

I think I'm only maintaining one navigation controller in that hierarchy. I've never created other navigation controllers. I only push view after another.

Thank you everyone for the answers! I will give out the bounty soon, I'll let other people vote first before the bounty expires.

解决方案

After looking at it,the scenario seems to be same like me.What I faced for the first time when doing Tab+Navigation.

I am sure that there is some problem with your Tab+Navigation based application. Although it shows the Tab as well as navigation are not able to navigate the basic flow.And it is very difficult to solve your problem with such less code.

Instead of this, I had an alternate solution for the same:

Once you have a tab bar in a XIB, the easiest way to approach this is to drag a UINavigationController object over from the Library window (looks like a left nav bar button on a gold background) into the Tree View for your tab bar (the text only view, not the GUI). Place it under the tab bar, then drag your existing view controller under the tab bar controller instead of under the tab bar.

When you go to view that tab you should then see a navigation bar on the top of it... if you are loading the navigation controller from another xib, you'll modify the nav bar in the tab bar xib.

else you can below you can follow the best url for the same:

http://books.google.co.in/books?id=2yYlm_2ktFYC&pg=PA179&lpg=PA179&dq=navigation+with+the+tab+based+application+iphoneSDK&source=bl&ots=nf2YYjX5Am&sig=COpHj9wOtsDChQBglpsljSTsElw&hl=en&ei=3ZoFTeGSOI_tsgbc_Iz6CQ&sa=X&oi=book_result&ct=result&resnum=6&ved=0CDAQ6AEwBQ#v=onepage&q&f=false

http://www.youtube.com/watch?v=LBnPfAtswgw

Hope this will surely solve your problem.

这篇关于将UIViewController推送到NavigationController实际上并不推送视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆