如何在viewcontroller上添加一个uinavigationitemviewController

&//获取view的controller&&&- (UIViewController *)viewController {&&& & &for (UIView* next = [self superview]; next = next.superview) {&&& & & & &UIResponder *nextResponder = [next nextResponder];&&& & & & &if ([nextResponder isKindOfClass:[UIViewController class]]) {&&& & & & & & &return (UIViewController *)nextR&&& & & & &}&&& & }&&& & &&&&} &
这是一个封装好的方法,直接创建一个ViewController的对象就可以调用该方法。
& & & & & &&for (UIView *subView in view.subviews) {
& & & & & & & & if ([subView isKindOfClass:[UIButton class]]) {
& & & & & & & & & & NSLog(@"subview==%@",subView);
& & & & & & & & &&
& & & & & & & & & & }
& & & & & & & & }
用该方法遍历UIView上的所有控件,就可以获得某种控件,再配合tag可以取到某一个具体的控件。 &
UINavigationController *parentViewController =& (UINavigationController*)self.navigationController.parentViewC
&NSLog(@"parentViewController==%@",parentViewController);
这个方法可以获取父类的ViewCOntroller
阅读(...) 评论()UITabBarController中添加UINavigationController
使用UITabBarController来切换视图被广泛使用在程序中,比如微博、QQ里面都使用UITabBarController来切换视图。UINavigationController也是用来操作视图的切换,它使用都原理是堆栈,将视图一个一个压进栈中,然后再将视图从栈中提取出来。
将这两个整合起来操作视图会让你的程序使用起来更加流畅。下面来说说怎么整合UITabBarController和UINavigationController来操作视图。
新建的工程的类型我这里不是使用那种带有UITabBarController的工程。首先呢,如果你想要你整个工程的所有视图都包含有UITabBarController,就要在AppDelegate中定义UITabBarController,在AppDelegate.m中实例化各个ViewController,在将viewcontroller推到UINavigationController中,再将UINavigationController都添加到一个NSArray中,然后再指定UITabBarController
的方法viewControllers等于这个数组,设置默认选中的UITabBar可以使用方法:tabBarController.selectedIndex
= 0;然后指定程序的rootViewController,再将UITabBarController添加到window中。然后跳转界面的时候使用UINavigationController的pushViewController方法来跳换视图,在第二个视图当中UINavigationController会自动为你创建一个返回按钮。
如果你想某个视图才开始使用UITabBarController,比如登陆界面和程序引导界面就可以不用,方法也一样,就多创建一个viewcontrollersubclass,在这个类中添加视图到UINavigationController中,再将UINavigationController添加到UITabBarCOntroller中,一样的道理。
就这样,UITabBarController和UINavigationController就整合起来啦。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&关于UIViewController添加UINavigationBar的详细实现方法
1,如果你创建的Controller本身就是UINavigationController,你可以直接在当前的UIViewController的ViewDidLoad中直接写代码,如下:
- (void)viewDidLoad
Add our custom add button as the nav bar's custom right view
UIBarButtonItem *addButton =
[[[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"AddTitle", @"")
& & style:UIBarButtonItemStyleBordered
& target:self
& action:@selector(addAction:)] autorelease];
self.navigationItem.rightBarButtonItem = addB
如果你创建的Controller是UIViewController,你可以直接在当前的viewDidLoad中调用下面这个函数:
- (void)setNavigationbar
& & CGRect&screenRect =
[[UIScreen mainScreen] bounds];
& & UINavigationBar *navigationBar =
[[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0,&screenRect.size.width,
& & nav.tintColor = COLOR(200, 100, 162);;
& //创建UINavigationItem
& UINavigationItem *&navigationBarTitle
= [[UINavigationItem
initWithTitle:@"创建UINavigationBar"];
[nav pushNavigationItem:&navigationBarTitle&animated:YES];
& & [self.view addSubview:&navigationBar];
//创建UIBarButton
可根据需要选择适合自己的样式
& UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply
target:self action:@selector(navigationBackButton:)];
& //设置barbutton
& &&navigationBarTitle.leftBarButtonItem
& & [navigationBar&setItems:[NSArray
arrayWithObject:&navigationBarTitle]];
开发过程中,有很多东西过段时间不用可能就会忘记,不过没关系,懂得怎样去查看帮助文档,怎样去解决问题才是关键!
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。怎么强制某个viewcontroller横屏显示呢?
[问题点数:30分,结帖人fisea]
怎么强制某个viewcontroller横屏显示呢?
[问题点数:30分,结帖人fisea]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
本帖子已过去太久远了,不再提供回复功能。

我要回帖

更多关于 mvc view controller 的文章

 

随机推荐