0
私は同じ情報を共有する2つのプロトタイプセルを持つテーブルビューを持っています。 「CardList」ボタンをタップすると、すべてのセルが1つのセルサイズから小さいサイズに移動し、逆も同様です。最初のトランジションはうまく動作しますが、小さなセルから大きなセルに戻ると、セルの高さは、設定した338ではなく、約50ポイントです。また、これが2つの異なる細胞を持つことによってこれを行う最善の方法であるかどうかも疑問です。私はちょうど1つのセルを持って、それを並べ替えるべきですか?あなたは、このメソッドを使用する必要があり、適切な方法でcellRowの高さを設定するこれを実行する最良の方法であるかどうか不思議です。テーブルビュースイッチングセルサイズ
var CellSize = Int()
@IBAction func CardList(sender: AnyObject){
if (sender.titleLabel!?.text == "Card")
{
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 338
self.CellSize = 2
self.tableView.reloadData()
sender.setTitle("List", forState: UIControlState.Normal);
}
else
{
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 142
self.CellSize = 1
self.tableView.reloadData()
sender.setTitle("Card", forState: UIControlState.Normal);
}
}
////////////////
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if CellSize == 1 {
let cell = self.tableView.dequeueReusableCellWithIdentifier(
"ResultsCell2", forIndexPath: indexPath)
as! ResultsCell2
let row = indexPath.row
cell.Name.text = Names[row]
cell.Image.image = UIImage(named: Images[row])
cell.Price.text = Prices[row]
return cell
}
else
{
let cell2 =
self.tableView.dequeueReusableCellWithIdentifier(
"ResultsCell", forIndexPath: indexPath)
as! ResultsCell
let row = indexPath.row
cell2.Name.text = Names[row]
cell2.Image.image = UIImage(named: Images[row])
cell2.Price.text = Prices[row]
return cell2
}
}
問題は、デバイスが画面サイズを変更したときに、セルがアスペクト比に基づいてサイズ変更されることです。回答thoのための笑感謝! –