[ios开发]2020.9.6-2020.9.12笔记

  1. 用UINavigationController的时候使用pushViewController:animated
    ----返回之前的视图[[self navigationController] popViewControllerAnimated:YES];
    —ps:push以后会在navigation的left bar自动添加back按钮,它的响应方法就是返回。所以一般不需要写返回方法,点back按钮即可。
  2. 其他时候用presentModalViewController:animated
    [self presentModalViewController:controller animated:YES];//YES有动画效果
    -----返回之前的视图 [self dismissModalViewControllerAnimated:YES];
  3. 相比较于C++,init更像是缺省构造,initWith…像是提供实参的构造
  4. 感觉写一个仿写界面主要问题就是
    1.传值
    2.自定义cell
    3.uinavigation的创建以及导航栏的创建
  5. UIButton的几个状态
    UIControlStateNormal = 0, 常规状态显现

UIControlStateHighlighted = 1 << 0, 高亮状态显现

UIControlStateDisabled = 1 << 1, 禁用的状态才会显现

UIControlStateSelected = 1 << 2, 选中状态

UIControlStateApplication = 0x00FF0000, 当应用程序标志时

UIControlStateReserved = 0xFF000000 为内部框架预留,可以不管他

  1. 折叠cell的创建方法:
    1. 正常创建tableview
    2. 在viewForHeaderInSection中创建一个UIControl控件(UIControl控件的介绍:https://blog.csdn.net/iteye_9214/article/details/82283002?utm_medium=distribute.pc_relevant.none-task-blog-searchFromBaidu-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-searchFromBaidu-2.channel_param)
    3. 通过UIControl的tag来记录所在的组,然后设置点击事件UIControlEventTouchUpInside,点击事件传递参数UIControl
    4. 创建一个布尔变量的数组 在tableview中的创建numberOfRowsInSection时选择,布尔变量为yes时,那么每一组中的rows为0,否则就正常创建。后面在点击事件中通过刚刚传递的参数的tag值来确定为哪一个组,后取需要的布尔数组的反(就是加一个感叹号)
    5. 在标志也更改了,就剩最后一步,点击时需要刷新列表,
    NSIndexSet * index = [NSIndexSet indexSetWithIndex:i];
       [_tableview reloadSections:index withRowAnimation:UITableViewRowAnimationAutomatic];

其中的重点代码:

//开始创建

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    if(flag[section] == YES){
    
    
        return 0;
    }
    return 8;
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    
    return 50;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    
   
    UIControl *view = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)];
    view.tag = section;
    view.backgroundColor = [UIColor grayColor];
    [view addTarget:self action:@selector(press:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 70, 30)];
    label.textColor = [UIColor blackColor];
    label.font = [UIFont systemFontOfSize:15];
    label.text = [NSString stringWithFormat:@"第%ld组",section];
    [view addSubview:label];
    return view;

}

-(void)press:(UIControl *)view{
    
    
    NSInteger i = view.tag;
       //取反
    flag[i] = !flag[i];
       //刷新列表
       NSIndexSet * index = [NSIndexSet indexSetWithIndex:i];
       [_tableview reloadSections:index withRowAnimation:UITableViewRowAnimationAutomatic];
}
@end

UINavigationController与UITabBarController

  1. UINavigationController继承自UIViewController,是一个基于栈的容器型控制器。既然是容器,它就能装一些东西,比如UIView能装各种组件(UILabel,UIButton等),UINavigationController装的是视图控制器。
    一个UINavigationController包含了几个部分,

Navigation Stack导航栈,它以栈的形式来管理视图控制器。栈的一个视图控制器(栈底),称为根视图控制器,其他称为子视图控制器。栈中的控制器可以通过self.navigationController找到UINavigationController的实例。

UINavigationBar导航条,栈中的视图控制默认会在顶部加一个导航条,虽然Navigation Bar显示在子视图控制器的界面上,但是它是由UINavigationController实例管理的,不过,导航条的内容却是由子视图控制器决定(通过self.navigationItem设置)。

UIToolbar工具栏,UINavigationController在子视图的底部提供了工具栏,默认不显示,也很少用到。

  1. 1.UITabBar
    下方的工具条称为UITabBar ,如果UITabBarController有N个子控制器,那么UITabBar内部就会有N 个UITabBarButton作为子控件与之对应。

注意:UITabBarButton在UITabBar中得位置是均分的,UITabBar的高度为49。

扫描二维码关注公众号,回复: 11878141 查看本文章
  1. UITabBarButton

UITabBarButton⾥面显⽰什么内容,由对应子控制器的tabBarItem属性来决定

以一个最简单的为例:这个就是在验证登陆过后的普通的界面

先创建每一个页面然后通过UINavigationController(导航控制器)来进行对视图控制器的操控

如何进行操控 首先先创建五个导航控制器 创建时使用提供实参的创建 每一个对应一个页面 使每一个都为一个新的根视图,然后通过一个新数组保存这5个导航控制器 再新创建一个tabbar来进行具体的页面切换的操作 将数组赋值给新创建的tabbar.viewcontroller 最后通过self.view.window.rootviewcontroller = 刚刚创建的tabbar来显示到view上
(tarbar和导航控制器相辅相成)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_46110288/article/details/108436518