UIViewController

2017年7月1日
1.UIViewController 有时候 view不现实在导航栏下面
原因:导航栏可能透明,导致,从顶部开始

解决

self.edgesForExtendedLayout = UIRectEdgeNone; //导航栏设置为有透明度,设置view不被导航栏覆盖```

补充 如果导航栏不透明,而且又不像往下偏移

self.extendedLayoutIncludesOpaqueBars = YES;

2017年5月24日 
1.删除子控制器

for (UIViewController *vc in self.childViewControllers) {
[vc removeFromParentViewController];
}

2.因为 view页面不能跳转,所以,你如果需要用到子控制器里面的跳转,需要添加[self addChildViewController:TCVC];
实现

-(void)addChildViewController
{
for (int i = 0; i < self.dataList.count; i++) {

    DiscoverSunViewController *TCVC = [[DiscoverSunViewController alloc]init];
    TCVC.disType = [(HuDisCanMatchButtonModel*)self.dataList[i] Id];
    TCVC.delegate = self;
    TCVC.view.frame = CGRectMake(width * i, 0, width, height);
    [_scrollView addSubview:TCVC.view];
    [self addChildViewController:TCVC];
} 

}

// DiscoverSunViewController.h

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    HuDiscoverListModel *model = self.myList[indexPath.row];
    HuDiscoverCourseDetailsViewController *details = [[HuDiscoverCourseDetailsViewController alloc]init];
    details.courseId = model.Id;
    [self.navigationController pushViewController:details animated:YES];
    }
2017年4月11日 
1.vc返回按钮过滤掉指定的页面
效果答题,进入分析界面,点击放回,不能返回到答题界面

![image.png](http://upload-images.jianshu.io/upload_images/3003454-261410b9c468be99.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
实现:

/**
当前页面点击返回按钮 过滤掉第一个指定类型的页面

@param curVc 当前页面
@param specialVc 过滤掉的指定页面
*/

  • (void)curVc:(UIViewController)curVc backPassSpecialVCClass:(NSString)specialVc;
    {
    NSArray *vcArray = curVc.navigationController.viewControllers;
    NSInteger count = [vcArray count];

    BOOL needPassTestPracticeVC = NO;

    if (count >= 2)
    {
    //倒数第二个开始,最后一个不要判断
    NSInteger i = count - 2;
    for( ; i > 0; i--)
    {
    UIViewController *vc = vcArray[i];
    if ([vc isKindOfClass:[NSClassFromString(specialVc) class]]) {
    needPassTestPracticeVC = YES;
    break;
    }
    }

      if (needPassTestPracticeVC) {
          [curVc.navigationController popToViewController:[vcArray objectAtIndex:i - 1] animated:YES];
      }else{
          [curVc.navigationController popViewControllerAnimated:YES];
      }
    

    }
    }

使用:
  • (void)backClick
    {
    //如果前一个页面是答题HuTestPracticeViewController,
    [HuConfigration curVc:self backPassSpecialVCClass:kHuTestPracticeViewController];
    }

2017年2月23日
1.底部menuBar 隐藏和显示接口

/**
隐藏和打开底部meubar

@param vc 需要隐藏的页面
@param flag 是否隐藏, yes隐藏 no显示
*/

  • (void)hideMenuBar:(UIViewController )vc withFlag:(BOOL)flag
    {
    UITabBarController CustemVc=(UITabBarController)vc.tabBarController;
    if(flag){
    if ([CustemVc isKindOfClass:[CustomMyViewController class]]) {
    [(CustomMyViewController
    )CustemVc hiddenTabBar];
    }else if ([CustemVc isKindOfClass:[TrainTabBarViewController class]]){
    [(TrainTabBarViewController)CustemVc hiddenTabBar];
    }
    }else{
    if ([CustemVc isKindOfClass:[CustomMyViewController class]]) {
    [(CustomMyViewController
    )CustemVc showInTabBar];
    }else if ([CustemVc isKindOfClass:[TrainTabBarViewController class]]){
    [(TrainTabBarViewController*)CustemVc showInTabBar];
    }
    }
    }
一般用法:

// HuTestPracticeViewController.m

  • (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [HuConfigration hideMenuBar:self withFlag:YES];
    }

  • (void)viewWillDisappear:(BOOL)animated
    {
    [super viewWillDisappear:animated];
    [HuConfigration hideMenuBar:self withFlag:NO];
    }

2017年1月18日
1.导航栏相关设置

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//导航透明
self.navigationController.navigationBar.translucent = YES;
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}

  • (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    //导航不透明
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
    }
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/3003454-86aa5dc40adfa468.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

2017年1月10日
1.页面的push 和 pop(非模态)

HuSessionListViewController *controller = [[HuSessionListViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
// HuSessionViewController.m

  • (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];
    }

-(void)back:(UIButton *)backBtn
{
[self.navigationController popViewControllerAnimated:YES];
}

1.1

MessageCenterController *messageVc = [[MessageCenterController alloc]init];
UINavigationController * Nav = [[UINavigationController alloc]initWithRootViewController:messageVc];
[self.window.rootViewController presentViewController:Nav animated:YES completion:nil];

1.2

//回到主界面
loginViewController *loginVc = [[loginViewController alloc]init];
[[[[UIApplication sharedApplication]windows]objectAtIndex:0]setRootViewController:loginVc];

2.设置rootViewController, (图片控制器无法加载出来,原因根视图是loginViewController,该页面不一定每次都存在,已经消失了)

[[UIApplication sharedApplication].keyWindow setRootViewController:custom];

//这种是模态方式添加页面,会是loginViewController 一直是rootViewController,导致IM发送图片,无法弹出图片选择框(loginViewController,已经登录过就不需要创建了,会报whose view is not in the window hierarchy)
//[self presentViewController:custom animated:YES completion:nil];

3.返回到指定页面(非一级一级返回)
3.1跳转到第一个同类界面的前一个界面

/**
跳转到第一个同类界面的前一个界面

@param vc 当前类界面
*/

  • (void) backFromFirstKindPage:(UIViewController*)controller
    {
    NSArray *vcArray = controller.navigationController.viewControllers;
    UIViewController *lastVc = nil;
    for(int i = 0; i < [vcArray count]; i++)
    {
    UIViewController *vc = vcArray[i];
    if ([vc isKindOfClass:[controller class]])
    {
    break;
    }

      lastVc = vc;
    

    }
    if (lastVc) {
    [controller.navigationController popToViewController:lastVc animated:YES];
    }
    }

使用:

pragma mark - PrivateFunction

  • (void)backClick
    {
    [HuConfigration backFromFirstKindPage:self];
    }
3.2也可以用下标的方式

[controller.navigationController popToViewController:[vcArray objectAtIndex:index] animated:YES];

viewControllers 数组日志
<__NSArrayI 0x6180000f6f00>(
<PersonalCenterViewController: 0x7fbe60e2a1a0>,
<HuSessionListViewController: 0x7fbe60e8ff90>,
<HuSessionViewController: 0x7fbe638435d0>,
<PatientIndexViewController: 0x7fbe63b175c0>,
<HuSessionViewController: 0x7fbe60cad2f0>,
<PatientIndexViewController: 0x7fbe60e2f320>,
<HuSessionViewController: 0x7fbe63898c30>,
<PatientIndexViewController: 0x7fbe60ccbf60>,
<HuSessionViewController: 0x7fbe60ccc540>,
<PatientIndexViewController: 0x7fbe60ed0300>,
<HuSessionViewController: 0x7fbe60f11640>,
<PatientIndexViewController: 0x7fbe60cf6c30>,
<HuSessionViewController: 0x7fbe60f13c90>
)


如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,524评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,869评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,813评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,210评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,085评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,117评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,533评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,219评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,487评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,582评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,362评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,218评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,589评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,899评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,176评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,503评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,707评论 2 335

推荐阅读更多精彩内容