Xcode 6.4 IOS 8.4,如果我滑动自定义的单元格,有些单元格会混乱,但慢慢滑动单元格会正常!我认为原因是单元格的重用。但我不知道如何解决它!
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"MyTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
self.tableView.estimatedRowHeight = 200;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.allowsSelection = NO;
self.tableData = @[@"1\n2\n3\n4\n5\n6", @"123456789012345678901234567890", @"1\n2", @"1\n2\n3", @"1", @"1\n2\n3\n4\n5\n6", @"123456789012345678901234567890", @"1\n2", @"1\n2\n3", @"1", @"1\n2\n3",@"1\n2\n3"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.tableData.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.textView.text = self.tableData[indexPath.row];
cell.isShowView = YES;
cell.button.hidden = NO;
cell.intextView.hidden = NO;
if(indexPath.row % 2 == 0) {
cell.isShowView = NO;
cell.button.hidden = YES;
cell.intextView.hidden = YES;
}
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
return cell;
}
自定义Cell.m
- (void)awakeFromNib {
self.isShowView = YES;
}
-(void)updateConstraints {
if(self.isShowView == NO) {
[self.content mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@0);
}];
NSLog(@"self.isShowView == NO");
}
[super updateConstraints];
}