1
嘗試創建一個簡單的表格,其中包含按鈕,這些按鈕是在運行時生成的;該表出現並具有正確數量的行等,但行看起來是空的。以編程方式添加到UITableViewCell中的UIButton永遠不會出現
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
// The NavItem class is a "Josh Bloch enum" with n ordered members
NavItem item = NavItem.ByOrder(indexPath.Row);
var cell = tableView.DequeueReusableCell(item.Name);
if (cell == null)
{
cell = new UITableViewCell(UITableViewCellStyle.Default, item.Name);
UIButton button = UIButton.FromType(UIButtonType.RoundedRect);
button.SetTitle(item.Name, UIControlState.Normal);
cell.ContentView.AddSubview(button);
// cell.TextLabel.Text = item.Name;
// cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
}
return cell;
}
沒有按鈕,註釋掉的純文本版本可以正常工作。
我是iOS的全新人物,所以我認爲這裏有一些關於組件大小調整或定位或佈局的信息,我錯過了 - 任何人都知道它是什麼?
謝謝 - 這似乎這樣做,但現在我需要弄清楚如何設置錶行高度。 :) – 2010-10-06 16:22:43
好的,GetHeightForRow() - 這很容易。 – 2010-10-06 16:31:04