调用[detailviewcontroller setObject]时,prepareForSegue失败

时间:2011-12-06 09:11:09

标签: objective-c

- (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.Category = category;

它立即停在以下行,错误'线程1程序收到信号sigabrt'

#import "AppDelegate.h"

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

2 个答案:

答案 0 :(得分:0)

detailViewController中的对象可能无法理解消息setCategory:。调试控制台中应该有此错误消息。如果没有,请在调试控制台中发布 的消息。

顺便说一句,你不应该用大写字母开始属性名称(或方法名称)。这令人困惑。

答案 1 :(得分: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;
    }
}