开发者

IOS: use navigation controller in a subview

In a view of my program I have a button and with this button I open a subview; this subview is a view with a tableview. I want go to another view wh开发者_JAVA技巧en I push a row of the tableview so I want to make this with a navigation controller; how can I do this?


Your table view delegate will receive a tableView:didSelectRowAtIndexPath: message when you click on one of the table's rows.

You can put there your code to create the UINavigationController and push on to it your new view.

This sample code (from another answer of mine on S.O.) shows how you can do that:

 UINavigationController* navigation = [[UINavigationController alloc] init];
 iVkViewController *overviewViewController = [[iVkViewController alloc] init];
 overviewViewController.title = @"First";
 [navigation pushViewController:overviewViewController animated:NO];

This should help you getting things on track.

One side note: you might think of having a navigation controller from the very start, this would make your UI more "well-behaved", but this depends ultimately on your app requirements.


If UIViewController addSubView a view of UITableViewController,you want to push in the method of tableView:didSelectRowAtIndexPath,you should check if self.navigationController is nil. If it's nil,You probably should use

[self.parentViewController.navigationController pushViewController:controller animated:YES];

if self.parentViewController is also nil,Sometimes,you have to set a @property to point out the parentViewController In UITableViewController,like:

@property (nonatomic, weak) UIViewController *parentVC;

and in UIViewController:

UITableViewController *tableViewVC = [[UITableViewController alloc] init];
tableViewVC.parentVC = self;

In UITableViewController ,-tableView:didSelectRowAtIndexPath:

[self.parentVC.navigationController pushViewController:controller animated:YES];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜