Light's Blog

The best or nothing.

iOS知识小集-180723

| Comments

UITableView Delete Cell

调用deleteRowsAtIndexPaths:withRowAnimation:时界面出现诡异问题,删除一个cell之后无法继续删除下面的cell。
暂时解决办法是在数据源中删除对应数据后,直接reloadData而不再调用上述方法。

UITableViewCell高亮效果

重写-setHighlighted:animated:方法,当highlighted时改变背景颜色,非highlighted时通过动画修改回去。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
  [super setHighlighted:highlighted animated:animated];
  [self xg_setHighlighted:highlighted animated:animated color:[UIColor lightGrayColor]];
}

- (void)xg_setHighlighted:(BOOL)highlighted animated:(BOOL)animated color:(UIColor *)highlightedColor{
  if (highlighted) {
    self.contentView.backgroundColor = highlightedColor;
  } else {
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
      self.contentView.backgroundColor = [UIColor whiteColor];
    } completion:nil];
  }
}

Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy

viewDidLoad:时不能present viewController,改写为viewDidAppear:时进行操作。

Comments