2016-09-07 6 views
1

У меня есть контроллер вида с таблицей внутри, которая сгруппирована. Это создает очень странный сбой, который заставляет секционные титры показывать сбоку. Я привязал верхние, конечные, нижние и ведущие ограничения к супервину для представления таблицы, и я протестировал возвращение UITableViewCell() в cellForRowAtIndexPath, чтобы узнать, вызвала ли это ядро ​​эту проблему, но она все еще показывает это как это ,Заголовок заголовка UITableView Glitch?

var sectionTitles = ["Customer Orders", "Unprocessed Orders", "Processed Orders"] 


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

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return 1 
} 

func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? { 
    return sectionTitles 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ 
    let cell = tableView.dequeueReusableCellWithIdentifier(CONSTANTS.CELL_IDENTIFIERS.ORDER_CELL) as! OrderTableViewCell 
    return cell 
} 

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    // Perform segue to order list in future 
} 

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    return 117.0 
} 

enter image description here

ответ

0

После нескольких часов я понял, что я не реализует этот метод

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

Если у вас есть только один раздел вы не положить много названий. Если вместо этого вы хотите, чтобы дать название для каждой ячейки, вы должны добавить метку в настраиваемой tableViewCell и в вашем cellForRowAtIndexPath вы должны поставить что-то вроде этого (после того, как вы создали NSObject класс):

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ 
    let cell = tableView.dequeueReusableCellWithIdentifier(CONSTANTS.CELL_IDENTIFIERS.ORDER_CELL) as! OrderTableViewCell 

let order = Order[indexPath.row] 

cell.yourTitleLabel.text = order.title 

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