2016-03-30 37 views
0

UITableView'imde garip bir hata yaşıyorum. İki hücrem var, SummaryHeaderTableViewCell ve MapTableViewCell. 400 ve 200 piksel boyunda. İki satırım var ve ilk satırın özet hücresi olmalı ve ikincisi harita hücresi olmalı.Garip UITableView davranışı

Ama yine de, simülatörde görüşlerini şöyle gösteriyor:

enter image description here: Burada

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell: UITableViewCell 

    if indexPath == 0 { 

     let summaryCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SummaryHeaderTableViewCell 

     summaryCell.nameLabel.text = detailItem!["navn"] as? String 
     summaryCell.addressLabel.text = "\(detailItem!["adrlinje1"]), \(detailItem!["adrlinje2"])" 
     summaryCell.cityLabel.text = detailItem!["poststed"] as? String 

     let inspectionDate: String = detailItem!["dato"] as! String 
     summaryCell.inspectionDateLabel.text = self.convertDateString(inspectionDate) 

     cell = summaryCell 
    } 
    else 
    { 
     let mapCell = tableView.dequeueReusableCellWithIdentifier("MapCell", forIndexPath: indexPath) as! MapTableViewCell 

     // Set map options 

     cell = mapCell 
    } 

    return cell 
} 

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

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

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if (indexPath.section == 0) { 
     return 400.0 
    } else { 
     return 200.0 
    } 
} 

dinamik prototip ile film şeridi: İşte

enter image description here

kodudur

cevap

2

Siz heightForRowAtIndexPath yerine bölümün satır başvurmalıdır:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if (indexPath.row == 0) { 
     return 400.0 
    } else { 
     return 200.0 
    } 
} 
+0

Aaah, bana aptal .. –

1

Yalnızca UITableView tek section yaşıyorsanız ve farklı ürün iki farklı satırlar değil, bölümler üzerinde doldurulur.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    if indexPath.row == 0 { 
     let summaryCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SummaryHeaderTableViewCell 
     summaryCell.nameLabel.text = detailItem!["navn"] as? String 
     summaryCell.addressLabel.text = "\(detailItem!["adrlinje1"]), \(detailItem!["adrlinje2"])" 
     summaryCell.cityLabel.text = detailItem!["poststed"] as? String 
     let inspectionDate: String = detailItem!["dato"] as! String 
     summaryCell.inspectionDateLabel.text = self.convertDateString(inspectionDate) 
     return summaryCell 
    } 
    else 
    { 
     let mapCell = tableView.dequeueReusableCellWithIdentifier("MapCell", forIndexPath: indexPath) as! MapTableViewCell 
     // Set map options 
     return mapCell 
    } 
} 

Ayrıca

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if (indexPath.row == 0) { 
     return 400.0 
    } 
    else { 
     return 200.0 
    } 
} 
+0

elbette beni aptal. –