-1

我有一个 UITableViewController。我需要显示一个表格单元格,然后显示一个具有嵌入式 UITextField 的单元格。基本上我需要交替显示 tableView 数据源。请帮我解决这个问题。谢谢。

编辑#1:想象一下NSMutableArray *tableData;具有以下元素的表的数据源:

  • @"Apple"
  • @"Mango"
  • @"Watermelon"

我希望 UITableView 显示为:

  • 第一个细胞:苹果
  • 第二个单元格:输入数量的文本字段
  • 第三格:芒果
  • 第 4 个单元格:输入数量的文本字段
  • 第五格:西瓜
  • 第 6 个单元格:输入数量的文本字段
  • 第 7 格:保存按钮
4

1 回答 1

1

像这样使用 dataSource 方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  // Return the number of rows in the section.
  return ([m_tableData count]*2)+1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   if(indexPath.row == [m_tableData count]*2)
   {
      //cell with button
   }
   else
   {
    if(indexPath.row == 0 || indexPath.row%2 == 0)
    {
      //cell with label for displaying values
    }
    else
    {
      //Load a cell that has an embedded UITextField
    }
   }
}
于 2012-09-04T11:01:50.050 回答