IOS How to alter an existing UI to use a new navigation controller
Ok, I'm having trouble with this.
I started an Application with a UITableViewController custom class called MainView.
In interface builder I modified the view so that there is a text box and a button on top and a UITableView. Connected the data source and delegate to the MainView class, and programmed in all the code to use the text field as a search field, the button as a search trigger, and then programmed in the proper delegate methods to populate the UITableView. This works perfectly.
Now the next step was to use the
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
method to be able to show a webview with a link related to the selected row. So reading I see that I need to add a UINavigationController to the mix ( so as to get the toolbar and navigation bar etc..).
Now I tried this: add a navigation controller from the Interface builder, and connect to the appdelegate, and an outlet
#import
@interface ComparateurAppDelegate : NSObject {
UIWindow *window;
UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end
then in the implementation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
}
this launches ok, same as before, and I don't have the top bar I should have. plus when I try to push a new view in it does nothing.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WebViewController *wvc = [[WebViewController alloc] initWithNibName:@"WebViewController.nib" bundle:nil];
[self.navigationController pushViewController:wvc animated:YES];
[wvc release];
}
I know the code is running because I nslog it. but nothing is happening. WebViewController.nib is the nib file I created ( empty right now) so that I populate it with a UIwebview.
My guess at this moment is that the view hierarchy is not set ok.
So I tried a few things I can't remember exactly and got the toolbar on top of the window I already have, but with all the content inaccessible ( like if the toolbar was a modal dialog and I could not use the bottom one , or like a transparent view and you could see underneath to the first window that was stacked). I also tried creating programatically the UINavigation controller in the appDelegate like so
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIViewController *rootController = [[MainView alloc]init];
navigationController = [[UINavigationController alloc]initWithRootViewController:rootController];
[rootController release];
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
And all I got is an empty UITableView for an interface, and not the MainView.nib 开发者_Python百科( whose class is set as MainView).
TL;DR: Have an app that is working, want to add detailed view, and need to modify to a UINavigationController but can't seem to find the proper way to do it.
thanks in advance and sorry for the long post.
Try changing this:
UIViewController *rootController = [[MainView alloc]init];
To this:
UIViewController *rootController = [[MainView alloc]initWithNibName:@"MainView" bundle:nil];
精彩评论