2016-01-15 5 views
1

я хочу использовать функцию переключения внутри TabView cellForRowAtIndexPath изменить содержание таблицыпереключатель внутри Tableview cellForRowAtIndexPath

сценарий: переменная флаг должен выбрать, какой случай и вернуть его содержимое.

ошибка: я должен использовать возвратную ячейку вне функции переключателя, если я использую ее, все еще даю мне ошибку.

switch (flag){ 
    case 0 : 

     let cell:mineCell = tableView.dequeueReusableCellWithIdentifier("mineCell")as! mineCell 
     // User Name on cells 
     cell.usernameLabel.text = creator[indexPath.row] 

     //function 

      else { 
       print(error) 
      } 
     } 

     return cell 
     break 

    case 1 : 
     let cell:followingCell = tableView.dequeueReusableCellWithIdentifier("followingCell")as! followingCell 
     // User Name on cells 
     cell.followingNameLabel.text = creator[indexPath.row] 

    //ffuntion 

      else { 
       print(error) 
      } 
     } 

     return cell 

     break 
    case 2 : 

     //funtion 
     break 
    default: 
     break 

    } 



//*HERE i have to use return cell but if i use it will give me error in somehow * 

} 
+0

в умолчанию, вы должны вернуть UITableViewCell() Я думаю – Benobab

+1

где это "' if'" часть' еще { печать (ошибка) } '? –

ответ

1

Попробуйте это в методе cellForRow

switch (flag){ 

case 0 : 

     let cell:mineCell = tableView.dequeueReusableCellWithIdentifier("mineCell")as! mineCell 
     // User Name on cells 
     cell.usernameLabel.text = creator[indexPath.row] 

     //function 

      else { 
       print(error) 
      } 
     } 

     return cell 
     break 

    case 1 : 
     let cell:followingCell = tableView.dequeueReusableCellWithIdentifier("followingCell")as! followingCell 
     // User Name on cells 
     cell.followingNameLabel.text = creator[indexPath.row] 

    //ffuntion 

      else { 
       print(error) 
      } 
     } 

     return cell 

     break 
    }  
} 

Надеется, что это помогает.

0

Ваш cellForRowAtIndexPath должен возвращать UITableViewCell объект или подкласс его в каждом из возможных сценариев. Поэтому вы должны вернуть UITableViewCell() в свой случай по умолчанию, чтобы избавиться от вашей ошибки.

-1

Сначала вам нужно объявить объект UITableViewCell в глобальном масштабе.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell 

     switch (flag) { 
      case 0 : 
      { 
       cell = tableView.dequeueReusableCellWithIdentifier("mineCell")as! mineCell 
       // User Name on cells 
       cell.usernameLabel.text = creator[indexPath.row] 
       //function 
       if() 
       { 
       }else { 
        print(error) 
       } 
       return cell 
      } 

       break 
      case 1 : 
      { 

      cell = tableView.dequeueReusableCellWithIdentifier("followingCell")as! followingCell 
      // User Name on cells 
      cell.followingNameLabel.text = creator[indexPath.row] 

      //ffuntion 
       if() 
       { 
       } 
      else { 
       print(error) 
      } 
      return cell 
     } 
     break 
      default: 
       break 
     } 


    return cell 
    } 
Смежные вопросы