zoukankan      html  css  js  c++  java
  • 控件参数的选择

    在控制器的类扩展里面 咱们会通常定义控件
    
    1.和stroyBoard上面关联 这时候用weak去修饰
    因为当咱们从storyBoard移除时就不会再有强引用,会自己释放
    
    2.为了进行赋值   用weak 去修饰
    当咱们从一个作用域到另一个作用域时,必须要通过在类扩展里面进行一次声明属性,通过赋值,进行作用域的跳转
    
    3.控件进行懒加载 要用strong
    当控件不一定被创建的时候,如果用也是频繁的使用时 
    比如:
    #pragma mark - 重写didSelectRow.. 这个方法
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        
        // 取消默认选中的状态
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        
        // 选中这个cell 会产生一些别的事件,重写了 覆盖了父类的方法
        if (indexPath.section==0) {
            
            return;
        }
        // 根据索引值去返回对应的cell
        BFSettingsCell *cell= [tableView cellForRowAtIndexPath:indexPath];
        
        [self.view addSubview: self.textField];
        
        
        [self.textField becomeFirstResponder];
        
        self.selectCell=cell;
        
    }
    
    
    
    #pragma  mark - 控件的懒加载
    
    - (UIDatePicker *)datePicker{
        
        if (_datePicker==nil) {
            
            _datePicker=[[UIDatePicker alloc]init];
            
            // 显示模式
            _datePicker.datePickerMode=UIDatePickerModeTime;
            
            _datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh-Hans"];
        }
        return _datePicker;
    }
    
    
    
    - (UITextField *)textField{
        
        if (_textField==nil) {
            
            _textField=[[UITextField alloc]init];
            
            _textField.inputView=self.datePicker;
            
            _textField.inputAccessoryView=self.tool;
        }
        return _textField;
    }
    
    
    
    
    - (UIToolbar *)tool{
        
        if (_tool==nil) {
            
            _tool=[[UIToolbar alloc]init];
            
            // 这个工具条咱们一般只需要去设置高度就可以了
            _tool.height=44;
            
            UIBarButtonItem *cancle=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancleBtnClick)];
            
            UIBarButtonItem *done=[[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(doneBtnClick)];
    
            UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
            
            _tool.items=@[cancle,flexSpace,done];
    
    
            
            
        }
        return _tool;
    }
    
    
    就是不在事件中去创建,会消耗性能,降低效率,这时候就要去用到控件懒加载,在用的时候去创建,必须要用strong 若是weak 说不通
    
    
    4.系统的view 也是进行懒加载的,设置数据不要通过set方法,要在viewDidload方法中,当控制器加载完成后,不然会出现bug
  • 相关阅读:
    Django基础命令
    ubuntu中python项目独立的虚拟环境
    Springboot项目的小问题
    redis
    ubuntu系统根目录下各个目录用途说明
    SpringBoot 在IDEA中实现热部署
    SpringBoot访问不到webapp下的内容
    httpServeltRequest和Model传值的区别
    map的输出
    主流框架排名
  • 原文地址:https://www.cnblogs.com/zhubaofeng/p/5222161.html
Copyright © 2011-2022 走看看