UINavigationController导航控制器…
来源:互联网 发布:中科院人工智能研究所 编辑:程序博客网 时间:2024/04/28 23:21
1、RootView跳到SecondView
首先我们需要新一个View。新建SecondView,按住Command键然后按N,弹出新建页面,我们新建SecondView
2、为Button添加点击事件,实现跳转
在RootViewController.xib中和RootViewController.h文件建立连接
在RootViewController.m中实现代码,alloc一个SecondViewController,用pushViewController到navigationController中去,并为
SecondViewController这是title为
- -
(IBAction)gotoSecondView:(id)sender { -
SecondViewController *secondView = [[SecondViewController alloc] init]; -
[self.navigationController pushViewController:secondView animated:YES]; -
secondView.title = @"Second View" ; - }
这就是SecondView了。
3、添加segmentedController
在nav bar这样的效果是如何实现的呢?
这就是segmentedController。
3.1在RootViewController.m的viewDidLoad添加如下代码:
- NSArray
*array "鸡翅",@"排骨",= [NSArray arrayWithObjects:@ nil]; -
UISegmentedControl *segmentedController = [[UISegmentedControl alloc] initWithItems:array]; -
segmentedController.segmentedControlStyle = UISegmentedControlSegmen tCenter; -
-
[segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChang ed]; -
self.navigationItem.titleView = segmentedController;
3.2[segmentedController
- -(void)segmentAction:(id)sender
- {
-
switch ([sender selectedSegmentIndex]) { -
case 0: -
{ -
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@ "你点击了鸡翅"delegate:self "确定"cancelButtonTitle:@ otherButtonTitles:nil, nil]; -
[alter show]; -
-
} -
break; -
case 1: -
{ -
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@ "你点击了排骨"delegate:self "确定"cancelButtonTitle:@ otherButtonTitles:nil, nil]; -
[alter show]; -
} -
break; -
-
default: -
break; -
} - }
4、自定义backBarButtonItem
左上角的返回上级View的barButtonitem的名字是上级目录的Title,如果title或者适合做button的名字,怎么办呢?我们可以自己定义
代码如下:
- UIBarButtonItem
*backButton "根视图"= [[UIBarButtonItem alloc] initWithTitle:@ style:UIBarButtonItemStyleDone target:nil action:nil]; -
self.navigationItem.backBarBu
6、自定义title
UINavigationController的title可以用别view替代,比如用UIButtonUILable等,下面我用UIButton.
在SecondViewController.m中添加下面如下。
- -
( void)viewDidLoad - {
-
[super viewDidLoad]; -
UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect]; -
[button setTitle: @"自定义title" forState: UIControlStateNormal]; -
[button sizeToFit]; -
self.navigationItem.titleView = button;}
例子代码:https://github.com/schelling/YcDemo
原博客连接http://blog.csdn.net/totogo2010/
- UINavigationController导航控制器…
- UINavigationController导航控制器…
- UINavigationController导航控制器…
- 导航视图控制器UINavigationController
- 导航控制器 ( UINavigationController )
- 导航控制器UINavigationController
- UINavigationController导航控制器详解
- UINavigationController 导航控制器
- 导航控制器UINavigationController
- 导航控制器:UINavigationController
- 自定义UINavigationController(导航控制器)
- swift UINavigationController 导航控制器
- UINavigationController 导航视图控制器
- UINavigationController 导航控制器
- UINavigationController 导航控制器
- UINavigationController导航控制器
- UI UINavigationController导航控制器
- UINavigationController---导航控制器
- UITableView讲解
- UITableView概述
- 两种不同TableView的使用(代码)
- 使用xib定义一个自定义Cell
- UINavigationController导航控制器…
- UINavigationController导航控制器…
- UINavigationController导航控制器…
- TableView事例讲解
- UIScrollView的属性总结
- UIScrollView事例(代码)
- UIScrollView详解
- iOS项目常用第三方开源库网址
- jsp+Servlet学习(一)简单实例
- 联网请求