2015-05-05 4 views
2

Я новичок в быстрое и объектно-ориентированном программирование,стремительных созданы секции UITableView

Я пытаюсь сделать некоторые отображения даты в секциях в моем UI табличного

Я хочу, чтобы изменить заголовок из них разделы вручную

вот мой код:

let section1 = 
    ["this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text",] 
let section2 = 
    ["this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text", 
    "this is used tot test the lenght of the text",] 

тогда мой метод, чтобы загрузить его

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return 5 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{ 
    return self.section1.count; 
} 

func tableView(tableView: UITableView, 
    cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:"cell") 
    cell.textLabel!.text = section1[indexPath.row] 
    cell.textLabel!.numberOfLines = 3 

    return cell 
} 

Я создал несколько постоянную для них, но они не должны быть разделены (Они постоянными они не изменятся)

мне просто нужно 5 различных секций для моих данных

спасибо много

ответ

2

вместо ячейки для строки с индексом пути реализации этого метода делегата:

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
    if section == 0 { 
    tableView.headerViewForSection(section)?.textLabel.text = section1[section] 
    } else if section == 1 { 
    //and so on for the number of sections you need. 5 or what evet. 
    } 

}

+0

Спасибо, что я уже сделал это и забыл об этом вопросе, но это именно то, что я сделал, и он работает! – Jp4Real

Смежные вопросы