ios - 是否可以不重用 UITableView 中的特定单元格?

标签 ios objective-c uitableview

我想在 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/

相关文章:

ios - UIButton 的标题颜色不会在突出显示/选定时改变,但背景颜色会

objective-c - 台风:注入(inject) View Controller 提供程序

ios - 重用自定义 tableViewCell 单元格中的隐藏按钮 [ios]

ios - 在 objective-c 中强制旋转

iOS - 是否可以向服务器发送连续连接请求?

ios - indexPath.row 处的 prepareForSegue EXC_BAD_ACCESS

ios - 无法为 iOS Swift 运行 Google Calendar API 示例代码

ios - 如何显示一个 ViewController 然后关闭它以显示一个 UISplitViewController?

uitableview - 设置分组 TableView 背景颜色

ios - 从 TableView Controller 中的静态单元格触发方法