防止cell中添加控件重复

2017-08-29  本文已影响0人  Flutter求学者

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdetify = @"cell";
UITableViewCell *tvCell = [tableView dequeueReusableCellWithIdentifier:cellIdetify];

if(tvCell == nil)
{
    NSLog(@"cell = nil");
    tvCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdetify] autorelease];
}else{     //如果不增加下面这个判断,tableview 再滑动后,会有重影,或者在被选中后会有重影
    NSLog(@"cell !=nil ");
    NSArray *views = [tvCell subviews];
    for (UIView *obj in views) {
        if (obj.tag==1000 || obj.tag==2000) {
            NSLog(@"cell 要删除的子画面是:%@",[obj class]);
            [obj removeFromSuperview];
        }
    }
上一篇下一篇

猜你喜欢

热点阅读