简体   繁体   English

PushViewController什么都不做

[英]PushViewController doesn't do anything

This is the first time I'm trying to implement navigation from a tableView cell to another tableView using UINavigationController and it doesn't work for me. 这是我第一次尝试使用UINavigationController实现从tableView单元格到另一个tableView的导航,这对我不起作用。 I'm NOT using nib file and I have a simple tableView that I present it in a modal dialog in my app, it works fine, now I added the disclosureInidcator to one of it's cell, to make the user enable to choose from a fixed number of options available from another list(tableView). 我没有使用nib文件,我有一个简单的tableView,可以在应用程序的模式对话框中显示它,它可以正常工作,现在我在其中一个单元格中添加了displayInidcator,以使用户能够从固定选项中进行选择另一个列表(tableView)中可用的选项数。 For this purpose I have another class that makes the second tableView. 为此目的,我还有另一个使第二个tableView的类。 the problem is now navigation from the cell(contains disclosure icon)in first tableview to second tableView doesn't do anything, no error, no nothing. 现在的问题是,从第一个表格视图中的单元格(包含公开图标)导航到第二个表格视图没有任何作用,没有错误,没有任何反应。 I guess the way I setup the navigation controller would be wrong, the code doesn't fall in delegate, or datasource of the second class at all. 我想我设置导航控制器的方式是错误的,代码没有落在委托中,或者根本没有第二类的数据源。

in First TableView in method : didSelectRowAtIndexPath I tried to catch that row, then call the second tableView like this: 在方法:didSelectRowAtIndexPath中的第一个TableView中,我尝试捕获该行,然后像这样调用第二个tableView:

 mySecondViewController *secondVC = [[[mySecondViewController alloc] initWithStyle:UITableViewStyleGrouped ]    autorelease];
  UINavigationController *navCont = [[UINavigationController alloc] initWithRootViewController: self];//not sure the first controller should act as the root controller?
 [navCont  pushViewController:secondVC animated:YES]; //it does nothing, no error,...

the second tableViewcontroller class contains all delegate and datasource methods, and initialization method: 第二个tableViewcontroller类包含所有委托和数据源方法以及初始化方法:

 - (id)initWithStyle:(UITableViewStyle)style 
 {
     if ((self = [super initWithStyle:style])) {

    }
    return self;
 }

  and declared in interface as:
 @interface stockOptionViewController : UITableViewController {

}

I tried to play with viewDidLoad, but didn't help. 我试图玩viewDidLoad,但没有帮助。

Please help me cause I have no clue and all sample codes found is based on using nib files. 请帮我,因为我一无所知,发现的所有示例代码均基于使用nib文件。

Thank, Kam 谢谢锦

Your navigation controller should be the root view controller of the app delegate's window, and the first view controller should be the root view controller of the navigation controller, then you can push new controllers onto it. 您的导航控制器应该是应用程序委托窗口的根视图控制器,而第一个视图控制器应该是导航控制器的根视图控制器,然后您可以将新的控制器推送到它。

Please see the documentation for UINavigationControlle r. 请参阅UINavigationControlle r的文档。

At the moment, you are creating a navigation controller but not putting it anywhere, so asking it to push new view controllers is a little pointless. 目前,您正在创建导航控制器,但没有将其放置在任何地方,因此,要求它推送新的视图控制器是没有意义的。 You have the right code, just not in the right order. 您拥有正确的代码,只是顺序不正确。

UINavigationController should be the root view controller. UINavigationController应该是根视图控制器。 In the current code, navCont is not on the view stack, so it won't work. 在当前代码中, navCont不在视图堆栈中,因此它将无法正常工作。 Instead of pushing myFirstViewController in your appDelegate, push the UINavigationController to the stack and add myFirstViewController as its root view controller. 代替将myFirstViewControllermyFirstViewController您的myFirstViewController中,将UINavigationController推送到堆栈并将myFirstViewController添加为其根视图控制器。

You can present view control modally without nav controller 您可以模态呈现视图控件而无需导航控制器

mySecondViewController *secondVC = [[[mySecondViewController alloc] initWithStyle:UITableViewStyleGrouped ]    autorelease];
[self presentModalViewController:secondVC animated:YES];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM