【发布时间】:2014-06-05 09:26:19
【问题描述】:
我注意到UITableViewCell 没有重复使用它的子视图,并且似乎在向上和向下滚动时被释放。我正在创建UITableViewCell 子视图并在viewDidAppear 上对其进行动画处理。我只想这样做一次,然后我希望子视图永远留在 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;
}
【问题讨论】:
-
accountsListBaseCell是什么? -
已编辑。这是实际的单元格名称..我正在尝试创建示例。
-
上下滚动时怎么知道它的子视图被释放了?我发现你在创建
customeView的框架时没有设置它。 -
我正在设置它的框架和其他配置,并在 viewDidAppear 上对其进行动画处理。当我上下滚动 if(!customCell.customeView) 条件变为真时,情况不应该如此。
-
我没有发现你的代码有什么问题,但我认为有一些冗余代码。
customCell.customeView = (CustomeView*)[customCell.contentView viewWithTag:101];这行可以省略。
标签: ios uitableview subview