首页 技术 正文
技术 2022年11月22日
0 收藏 392 点赞 3,941 浏览 1872 个字

给单独的viewcontroller或者在Appdelegate的主页面添加导航条,只要在viewcontroller上添加navigationcontroller,在添加此navigationcontroller即可

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

ViewController *mainView = [[ViewController alloc]init];

UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:mainView];

navi.navigationBar.backgroundColor = [UIColor blueColor];

[self.window setRootViewController:navi];

[self.window makeKeyAndVisible];

return YES;

}

导航条的字体和颜色的设置

self.navigationController.navigationBar.titleTextAttributes
=  [NSDictionary dictionaryWithObject:[UIColor whiteColor]
forKey:UITextAttributeTextColor]; // — 字体颜色

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@”BJ.png”] forBarMetrics:UIBarMetricsDefault]; // — 背景色

导航条跳转页面的考虑对于用navigationcontroller来跳转页面的时候,其实是执行堆栈的进栈和出栈的操作,要想释放内存,那么在来回跳转的时候,就要考虑几个问题了1 A =>B=>C=>D,
D=>A 有根视图的话 (HOME)
[self.navigationController popToRootViewControllerAnimated:YES]; 
D=>C  (每一个界面返回上一层)
[self.navigationController popViewControllerAnimated:YES]; 
返回到上一层,并且传递参数
CViewController *cvc = [CViewController alloc]init];
cvc.str = self.str;
[self.navigationController popToViewController:cvc animated:true];
返回到上一层后,上一页面显示后要接收参数,并刷新。注意此时应该在viewDidAppear中进行判断并接收传递的值
-(void)viewDidAppear:(BOOL)animated
{
  //判断并接收返回的参数
}

2  A =>B=>C=>D=>E,E=>B=>C=>E因为B在之前已经出现过,不能在E中直接PUSH到B,因为那样已经是两个B了,增加内存,所以在跳转的时候,就要进行判断是否之前已经出现过B了,出现过,则直接push。这样push到的是原有的B,不会在内存中重新生成一个B了。

NSArray *array = self.navigationController.viewControllers;

for (UIViewController *vc in array) {

if ([vc isKindOfClass:[BXXXViewController class]]) {

push VC;

}

或者知道每个界面的指针

[self.navigationController

popToViewController: [self.navigationController.viewControllers

objectAtIndex: ([self.navigationController.viewControllers count] -4)]

animated:YES];

在使用时,根据自己返回层的需要,只要改变一下“-4”这个数字就可以达到目的了

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844