2016-03-30 20 views
0

私のUITableViewに奇妙なバグがあります。私は2つの細胞、SummaryHeaderTableViewCellMapTableViewCellを持っています。彼らは400と200ピクセルの高さです。私は2つの行があり、最初の行はサマリーセルでなければならず、2番目の行はマップセルでなければなりません。奇妙なUITableViewの動作

しかし、それでもまだ、シミュレータ内のビューは次のように示しています

enter image description here

ここではコードです:ここでは

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 
    } 
} 

はダイナミックプロトタイプと絵コンテです:

enter image description here

答えて

2

あなた代わりheightForRowAtIndexPathセクションの行を参照する必要があります。あなたは

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

あー、私の愚かな... –

1

のみUITableViewで単一sectionを有しており、異なるアイテムは、二つの異なる行ないセクションに取り込まれています。

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 
    } 
} 

また

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

愚かな私は、もちろん。 –