2012-04-09 62 views
1

我想添加一個ViewController到我的TableView單元,但它在測試時沒有顯示出來。添加ViewController作爲UITableViewCell中的子視圖 - 沒有顯示

PhotoLocation是一個UIViewController子類。我在StoryBoard上創建了一個View Controller,並配置了一堆UILabels,UITextFields,UISwitch等。 PhotoLocation與該StoryBoard視圖控制器相關聯,其標識符是PhotoLocation。在一個單獨的控制器 - UITableViewController,我有一個工作的TableView與細胞填充各種信息,我想添加PhotoLocation VC作爲每個單元格的子視圖。 (注意:PhotoLocation是一個自由大小的VC,大小爲210x100)。

在我cellForRowAtIndexPath方法我做了以下內容:

// snip code above which sets up the cell and performs various other things 

PhotoLocation *photoLocation_ = [self.storyboard instantiateViewControllerWithIdentifier:@"PhotoLocation"]; 
[photoLocation_.view setFrame:CGRectMake(115, 0, 210, 109)]; 
[cell.contentView addSubview:photoLocation_.view]; 

return cell; 

當我運行應用程序的子視圖不會在細胞中出現。這裏有什麼我失蹤?

回答

2

如果我理解正確的話,嘗試做製作榫文件(文件 - >新建文件 - >用戶界面 - >查看)。刪除「視圖」並將表格視圖單元格拖出。按照您在文章中描述的方式進行佈局。在您的tableViewController做:

if (cell == nil) { 
    [[NSBundle mainBundle] loadNibNamed:@"TVCell" owner:self options:nil]; 
    cell = tvCell; 
    self.tvCell = nil; 
} 

是的原因,你不能有畫面2「viewControllers」在同一時間與控制器的控制器(標籤欄,導航,SPLITVIEW)除外。您正在嘗試將一個視圖控制器放入另一個視圖控制器中。

+0

交換和使用筆尖做的伎倆,謝謝。但是請注意,我確實將一個VC的加載作爲一個子視圖作爲一個單元格工作。我把它加載到單元格中,但是在選擇了單元格中的任何東西之後,我得到了一個運行時錯誤(我認爲是錯誤的訪問)。無論如何,筆尖是要走的路,再次感謝! – ElasticThoughts 2012-04-11 15:01:46

0

你試過嗎?

PhotoLocation *photoLocation_ = [self.storyboardinstantiateViewControllerWithIdentifier:@"PhotoLocation"]; 

[photoLocation_.view setFrame:CGRectMake(115, 0, 210, 109)]; 

[cell addSubview:photoLocation_.view]; 

return cell; 
相關問題