2014年1月27日 星期一

[Xcode] 在Static Cells表格上增加/改變accessoryType

[Xcode] 在Static Cells表格上增加/改變accessoryType 在使用動態表格(Dynamic Prototypes)時,我們常會在tableView:cellForRowAtIndexPath:方法裡添加程式碼來改變儲存格的AccessoryType屬性。但是若是使用靜態表格(Static Cells)便無法透過上述的方法來達成。
此時,我們可以透過透過tableView:willDisplayCell:forRowAtIndexPath:方法添加/改變AccessoryType,如下:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
未使用AccessoryType,以及使用後的執行結果如圖:
另外,AccessoryType有五種:
1. UITableViewCellAccessoryNone                           (預設,不使用Accessory)
2. UITableViewCellAccessoryDisclosureIndicator       (指向右側的灰色小箭頭)
4. UITableViewCellAccessoryDetailButton                (一個資訊的圖示)
3. UITableViewCellAccessoryDetailDisclosureButton  (綜合以上兩種)
5. UITableViewCellAccessoryCheckmark                   (核取的小勾勾)

若需要了解如何製作靜態表格,或是有相關的疑慮,可以參考看看「相關分享資訊」。
相關分享資訊:
[Xcode] 在一般的UI View Controller上建立Static Cells

沒有留言:

張貼留言