2011-12-06 75 views
0
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([[segue identifier] isEqualToString:@"ShowDetail"]) { 
     DetailViewController *detailViewController = [segue destinationViewController]; 

     ListViewCell *cell = (ListViewCell *)sender; 
     Category *category = cell.Category; 
     NSLog(@"cell category = %@", cell.Category.Name); 
     //[detailViewController setCategory:category]; 
     detailViewController.Category = category; 
    } 
} 

NSLog清楚地顯示了正確的cell.Category.Name,所以Category對象是好的。當[detailviewcontroller setObject]被調用時prepareForSegue失敗

但它在這一行

detailViewController.Category = category; 

它立刻在以下行停止與錯誤「主題1個節目接收信號SIGABRT」

#import "AppDelegate.h" 

int main(int argc, char *argv[]) 
{ 
    @autoreleasepool { 
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
    } 
} 

回答

0

舊代碼:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([[segue identifier] isEqualToString:@"ShowDetail"]) { 
     DetailViewController *detailViewController = [segue destinationViewController]; 

     ListViewCell *cell = (ListViewCell *)sender; 
     Category *category = cell.Category; 
     NSLog(@"cell category = %@", cell.Category.Name); 
     //[detailViewController setCategory:category]; 
     detailViewController.Category = category; 
    } 
} 

新代碼:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([[segue identifier] isEqualToString:@"ShowDetail"]) { 
     DetailTabViewController *detailTabViewController = [segue destinationViewController]; 

     ListViewCell *cell = (ListViewCell *)sender; 
     Category *category = cell.Category; 
     NSLog(@"cell category = %@", cell.Category.Name); 
     //[detailViewController setCategory:category]; 
     detailTabViewController = category; 
    } 
} 
0

大概在detailViewController對象不理解失敗消息setCategory:。在調試控制檯中應該有錯誤消息來達到這個效果。如果不是,請在調試控制檯中發佈的消息。

順便說一下,你不應該用大寫字母開始屬性名稱(或方法名稱)。這很混亂。

+0

這是我在調試控制檯 [的UITabBarController setCategory:]:無法識別的看到選擇發送到實例0x6a100a0。我會將屬性名稱更改爲小寫,不知何故,我對第一個字母帽感到滿意 – gangt

+0

因此,'detailViewController'指向'UITabBarController','UITabBarController'沒有category屬性或'setCategory:'方法。也許你的segue有錯誤的目的地。 –

+0

這是我第一次使用集成的界面構建器創建應用程序。我的意圖是在選擇tableviewcell時打開一個TabBarController。它顯示TabBar視圖很好但沒有傳遞對象。我甚至創建了一個繼承UITabBarController的viewcontroller,並在那裏添加了Category對象,但仍然出現相同的錯誤。 – gangt

相關問題