2016-02-07 82 views
0

「始終未能從‘UIViewController的’投射到不相關類型的‘TableViewCell’」演員總是失敗

我試圖操縱網點我TableViewCell控制器我得到這個錯誤。所以我想將一些數據從UIViewController轉換爲UITableViewCell。

enter image description here

+0

你可以在哪裏得到錯誤代碼? – Paulw11

+0

@ Paulw11你碰巧檢查附加的圖像? –

+0

不,我沒有注意到,但是您應該始終在您的問題中包含相關代碼,而不是將其包含在圖像中 – Paulw11

回答

0

-[UIStoryboardSegue destinationViewController]返回UIViewController*。假設TableViewCellUITableViewCell的一個子類,演員陣容沒有意義。從我看到的信息中,您需要檢查destinationViewController是否指向UITableViewController的實例,然後進行投射。

UIViewController *viewController = [segue destinationViewController]; 
if ([viewController isKindOfClass:[UITableViewControler class]]) 
{ 
    UITableViewController *tableViewController = (UITableViewController *) viewController; 
} 

從那裏,你可以訪問使用任何UITableViewController的方法的細胞,可能是那些實現UITableViewDelegateUITableViewDataSource。如果您需要更多實施特定控制,則在檢查destinationViewController是該類的一個實例後,您可以投射到TableVC