2015-12-14 2 views
0

По умолчанию в каждом разделе должно отображаться максимум три ячейки. Если какая-либо ячейка содержит более трех ячеек, она должна отображать опцию «показать больше». Если отображается больше, то я хочу отобразить остальные ячейки в этом конкретном разделе. Два дня я потратил, ничего не получилось. Отделы наверху стола. В зависимости от выбранного сегмента, tableview загружает ячейки. Этот код для каждого сегмента каждого раздела меняется, поэтому func cellForRowAtIndexPath: становится очень серьезным. Я грубо добавил код. Этот код - это то, что я пробовал.Показать больше в uitableview

if segmentName == .Feature || segmentName == .Services 
    { 
     if indexPath.section == 0 
     { 
      if boolShowFullFeature[indexPath.section] == false 
      { 
       if indexPath.row == showCells 
       { 
        return createShowMoreCell(indexPath.section) 
       } 
       else 
       { 
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SearchListViewCell 
        var firstTitle = "", secondTitle = "", thirdTitle = "", recomendValue = "", starValue = "" 

        (firstTitle, secondTitle, thirdTitle, recomendValue, starValue) = model.foodValue[indexPath.row] 
        cell.configureCell(firstTitle, secondTitle: secondTitle, thirdTitle: thirdTitle, recomendValue: recomendValue, starValue: starValue) 
        return cell 
+1

Это интересная информация. У вас тоже есть вопрос? – dasdom

+0

@Antony Что вы пробовали? Все работает? А что нет? – kostek

+0

@dasdom. Хороший способ уведомить меня .. :-) – Antony

ответ

0

Я действительно сделал это раньше. вот пример кода:

var objects = [["1","2","3"],["q","w","e","r","t","y"],["z","x","c","v","b","n","m"]] 
var sec = ["sec a","sec b","sec c"] 
var showallSec = 0 

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return sec.count 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    let items = objects[section].count 

    if items > 3{ 
     if section == showallSec-1{ 
      return items 
     } 
     return 4 
     } 
    return items 
} 

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

    let object = objects[indexPath.section][indexPath.row] 
    cell.textLabel!.text = object 
    if(indexPath.section != showallSec-1){ 
    if(indexPath.row == 3){ 
     cell.textLabel!.text = "show more" 
     }} 
    return cell 
} 

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
    return sec[section] 
} 

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    if(indexPath.row == 3){ 
     showallSec = indexPath.section + 1 
     tableView.reloadData() 
    } 
} 
Смежные вопросы