2016-02-17 7 views
0

У меня есть сегментированный контроллер, отображающий 3 разных табличных представления, причем случай 2 создает пользовательскую ячейку. Я получил пользовательскую ячейку для отображения в примере 2, но новая ячейка появляется в нижней части таблицы.пользовательская ячейка всегда должна быть на вершине таблицыView в сегментированном виде контроллера

Как заставить пользовательскую ячейку всегда отображаться в верхней части таблицыView?

@available(iOS 2.0, *) 
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    let myCell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) 

    switch(mySegmentedControl.selectedSegmentIndex) 

    { 

    case 0: 
     myCell.textLabel!.text = globalList[indexPath.row] 
     break 

    case 1: 
     myCell.textLabel!.text = friendsList[indexPath.row] 
     break 


    case 2: 

    // *** I want to add a Cell here with a "Add Item" IBAction --------------------- 

     if(indexPath.row == meList.count) { 

      myCell.textLabel?.text = "+ Add Item" 
      // add new row here 
      /* OR add new button here as cell's subview */ 
      // set frame of your button 
      // set target and selector method of button 
      // [cell addSubView: addButton] 

     } 
     else { 

      myCell.textLabel?.text = meList[indexPath.row] 
     } 

    default: 
     break 

    } 

    return myCell 

} 

ответ

0

Я думаю, что все, что вам нужно сделать, это проверить indexPath.row == 0 и добавить кнопку в этой ячейке. Else, настройте ячейку как обычно, но со сдвигом indexPath мой.

if(indexPath.row == 0) { 
    myCell.textLabel?.text = "+ Add Item" 
    // add new row here 
    /* OR add new button here as cell's subview */ 
    // set frame of your button 
    // set target and selector method of button 
    // [cell addSubView: addButton] 

} else { 
    myCell.textLabel?.text = meList[indexPath.row - 1] 
}