Loading UINavigationController subclass from a Nib

My situation is as follows: My class SettingsViewController is a subclass of UINavigationController . That class contains the logic of its rootViewController . For example, it acts as the delegate and data source for two table views in that root view controller.

I have no problem setting this up programmatically. In the initializer of SettingsViewController , I can create an additional UIViewController to serve as the root view controller, position the table views in its view, and set their delegates and data sources to self .

But I want to load that root view via a Nib. The problem is, I do not know how to connect that Nib with my SettingsViewController , how to set the delegates and data sources. The SettingsViewController is not accessible from within the Nib. 'File Owner' represents the root view controller, not the SettingsViewController .

How do I access my UINavigationController subclass from within my root view controllers Nib?

Thanks in advance.


you can declare a view inside your nib and set that of class SettingsViewController (if its a view).

or drag a view controller in IB and set this of class type SettingsViewController

//EDIT: so you want to present a view like MFMailComposerViewController . I also have a MessageViewController in my App which does nearly the same:

MessageViewController *mView = [[MessageViewController alloc]initWithNibName:@"MessageView" bundle:nil];
mView.navController = [[UINavigationController alloc] initWithRootViewController:mView];
[masterView presentModalViewController:mView.navController animated:YES];
[mView release];

notice that navController is a UINavigationController which is connected in IB to a navigation controller.


You won't have access to objects beyond your File's Owner in your nib. You would need to setup those properties programmatically after loading your view from that nib; your rootViewController could set its tables' delegates and datasources in its -viewDidLoad.

Additionally I have to ask, why did you subclass UINavigationController. The class references warns you that "This class is not intended for subclassing." There's probably a better place for your delegate/datasource logic if that's all you need this SettingsViewController for.

链接地址: http://www.djcxy.com/p/87714.html

上一篇: 更改WindowBased应用程序中的TabBarItem文本

下一篇: 从Nib加载UINavigationController子类