簡體   English   中英

如何從tableview為靜態單元格設置值(或者在init時從表視圖中獲取)

[英]How to set value from tableview for a static cell (or get it from the table view upon init)

我有一個帶有靜態單元格的UITableViewController,在故事板(Xcode 4)中創建。

對於每個單元格,我分配了一個TableViewCellController以便擁有自定義選擇器(http://www.wannabegeek.com/?p=104,以及此處使用的示例: http//timroadley.com/2012/02/26 / core-data-basics-part-6-core-data-uipickerview / )。

在我的UITableViewController中,我創建了一個新對象,我希望TableViewCellController可以訪問它。

UITableViewController被設置為TableViewCellController的委托,但是在TableViewCellController的init方法(自定義initializeInputView,從initWithCoder調用)中,委托尚未定義,因此我無法使用self.delegate訪問該對象。

在初始化時,將該值從UITableViewController傳遞給TableViewCellController或從TableViewCellController訪問它的最佳方法是什么?

謝謝

所以這就是我做的方式。 我在我的父UITableView中使用了willDisplayCell,並轉換了靜態單元控制器的類型,以便訪問它的dateValue屬性並初始化它。

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
            switch (indexPath.row) {
                case 0:
                    ((DateInputCellController *) cell).dateValue = self.event.date;
                    break;
                case 1:
                    ...
                    break;
                default:
                    break;
            }
            break;

        default:
            break;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM