2016-04-01 10 views
0

İki başlıklara sahip bir TableView oluşturmak çalışıyorum (Hesabı, Destek) ve sections.But metin başlıkları Ben hataları : '[Array <String>]' türünde '(bölüm)' türünde bir indeks değeri olamaz. Tip'(aka 'section.Type')

alıyorum ile bu sorunun cevabını takip : How do I populate two sections in a tableview with two different arrays using swift?

hatalar: enter image description here ve:

var myTitles = [["Delete current photo","Change profile picture","Change username","Change password"],["Help","Report a problem"]] 

let headerTitles = ["Acount", "Support"] 

override func viewDidLoad() { 
    super.viewDidLoad() 

} 

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return myTitles[section].count 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    return 3 //This is not complete yet. 
} 

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
    if section < headerTitles.count { 
     return headerTitles[section] 
    } 

    return nil 
} 

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

    cell.textLabel?.text = myTitles[indexPath.section][indexPath.row] 

    return cell 
} 
: enter image description here

Bu benim kodudur Burada section değerini alıyorsanız tüm

cevap

0

Öncelikle:

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return myTitles[section].count 
} 

Değişim sadece return myTitles.count için.