点语法的知识点
今天脑子发晕,有个效果一直没有出来 看了半天代码觉得没什么问题 逻辑什么的都是对的啊 然后 在快要崩溃的时候 我发现原来是点语法的错误:
之前错误的写法:
- (void)setSelected:(BOOL)selected { if (selected == YES) { _selectedIcon.hidden = NO; }else{ _selectedIcon.hidden = YES; } [super setSelected:selected]; }
正确的写法:
- (void)setSelected:(BOOL)selected { if (selected == YES) { self.electedIcon.hidden = NO; }else{ self.selectedIcon.hidden = YES; } [super setSelected:selected]; }
//懒加载
- (UIImageView *)selectedIcon { if (_selectedIcon == nil) { _selectedIcon = [[UIImageView alloc]initWithFrame:CGRectMake((self.width-55*[UIScreen mainScreen].bounds.size.width/375)/2, (self.height-55*[UIScreen mainScreen].bounds.size.width/375)/2-20, 55*[UIScreen mainScreen].bounds.size.width/375, 55*[UIScreen mainScreen].bounds.size.width/375)]; _selectedIcon.clipsToBounds = YES; _selectedIcon.layer.cornerRadius = 55*([UIScreen mainScreen].bounds.size.width/375)/2; _selectedIcon.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7]; _selectedIcon.contentMode = UIViewContentModeCenter; _selectedIcon.image = [UIImage imageNamed:@"interest_page_selected_icon"]; _selectedIcon.hidden = YES; [self addSubview:_selectedIcon]; } return _selectedIcon; }
看着两个代码作用是一样的 但是涉及到点语法 所以差别挺大的:点语法的本质是调用get方法和set方法。同时点语法会调用懒加载 下划线的方法不会!!
三四个小时的时间都在找问题所在 这是个很小的点 很容易忽略 同时也是很重要的一个点 希望不要再犯类似错误!!!!