我想在 UITableView
的第一行添加一些特殊效果,但是当我向下滚动表格 View 时,其他单元格也会出现(因为单元格可重用性?)。那么有什么方法可以阻止任何特定单元格的重用?我尝试将 nil
作为第一个单元格的 reusableIndentifier 传递,但它给了我错误(插入失败)。
我从 viewDidApper
方法调用此方法,用于第一行的一些动画-
-(void)openSubmenuForFirstRow{
stIndex = 0;
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
StoreCell* sCell = (StoreCell *)cell;
UIView* mainView = [sCell viewWithTag:101];
UIView* subView = [sCell viewWithTag:102];
[UIView animateWithDuration:0.3 animations:^{
CGRect rect = subView.frame;
rect.origin.x = 0;
subView.frame = rect;
CGRect mainViewRect = mainView.frame;
mainViewRect.origin.x = 117;
mainView.frame = mainViewRect;
}];
}
但是当我滚动表格 View 时,我在其他几个单元格上看到了这个动画。 任何帮助或建议将不胜感激。
最佳答案
您可以使用两个单元格 CellIdentifire。一个用于第一行,第二个用于其他行。检查 indexPath.row。如果它是 0,则使用 cellidentifier1,否则使用 cellidentifier2。
在第一行使用它:
UITableViewCell* cell;
if(indexPath.row == 0){
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell1"];
}
else{
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell2"];
}
if (cell == nil) {
if(indexPath.row == 0){
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"Cell1"];
}
else{
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"Cell2"];
}
}
关于ios - 是否可以不重用 UITableView 中的特定单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24675812/