iOS心得1

1、覆写已经存在的方法,可以解决意想不到的问题;

collectionViewCell中本身的selected方法,可以通过覆写selected属性的set方法,对不同状态做出操作;也或者是方法的覆写;


iOS心得1_第1张图片
image.png
//例如
-(void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if (selected) {
        //选中时
        self.celltextLabel.textColor = KBlueTextColor;
        
        
        self.contentView.layer.borderColor = KBlueTextColor.CGColor;
        self.contentView.layer.borderWidth = 1;
        self.contentView.layer.cornerRadius =2.5;
//        [self.contentView addLayerLineWithLineWidth:1 withLineColor:KBlueTextColor withCornerRadius:2.5];

    }else{
//        //非选中
        self.celltextLabel.textColor = KgrayLabelLineColor;
        
        self.contentView.layer.borderColor = KgrayLabelLineColor.CGColor;
        self.contentView.layer.borderWidth = 1;
        self.contentView.layer.cornerRadius =2.5;
//        [self.contentView addLayerLineWithLineWidth:1 withLineColor:KgrayLabelLineColor withCornerRadius:2.5];
    }
}

2.tableview的raloadData回到主线程

raloadData:会重新调用tableView的代理;

[AQNetworkManager POST:url parameters:params success:^(id responseObject) {
  @strongify(self);
  NSNumber *state_code = responseObject[@"state_code"];
  if ([state_code isEqualToNumber:@8000]) {
    dispatch_async(dispatch_get_main_queue(), ^{
      NSArray *data = responseObject[@"data"];
      
      if (!data) {
   
  } else {
    dispatch_async(dispatch_get_main_queue(), ^{
      
      [self.tableView.mj_header endRefreshing];
      [self.tableView tableViewShowMessage:@"目前还没有课程内容" ForDataCount:self.dataArray.count];
      [self.tableView reloadData];
      return;
    });
  }
  
} failure:^(NSError *error) {
  dispatch_async(dispatch_get_main_queue(), ^{
    
    [self.tableView.mj_header endRefreshing];
    [self.tableView tableViewShowMessage:@"目前还没有课程内容" ForDataCount:self.dataArray.count];
    [self.tableView reloadData];
    return;
  });
}];

你可能感兴趣的:(iOS心得1)