iOS UITableViewCell发布子视图

时间:2014-06-05 09:26:20

标签: ios uitableview subview

我注意到UITableViewCell没有重复使用它的子视图,似乎在向上和向下滚动时被释放。我正在创建UITableViewCell子视图并在viewDidAppear上设置动画。我只希望这样做一次,然后我希望subview永远保留在ContentView中,直到视图消失。所以我做了一些我认为正确的方法,但不确定是什么问题;有人可以帮忙吗?

UINib *nib1 = [UINib nibWithNibName:@"CustomCell" bundle:nil];
[self.tableView registerNib:nib1 forCellReuseIdentifier:@"CustomCell"];

@interface CustomCell : UITableViewCell

@property (nonatomic) IBOutlet UILabel *title;
@property (nonatomic) CustomeView *customeView;

@end

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      static NSString cellIdentifier = @"CustomCell";
      CustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:accountCellIdentifier forIndexPath:indexPath];

    ......

    customCell.customeView = (CustomeView*)[customCell.contentView viewWithTag:101];

   if(!customCell.customeView) {
      customCell.customeView = [CustomeView new];
      //configure customview...                                  
      customCell.customeView.tag = 101;
      [customCell.contentView addSubview:customCell.customeView];
   }

   return cell;
}

1 个答案:

答案 0 :(得分:0)

尝试将您的媒体资源类型更改为strong:

@property (strong, nonatomic) CustomeView *customeView;