-1

这是我的代码:

- (IBAction) buttonPressed:(id)sender
{
    DestinationViewController *destinationViewController = [[self.storyboard instantiateViewControllerWithIdentifier:@"Destination"] autorelease];
    destinationViewController.title = @"image property";
    destinationViewController.img = [UIImage imageNamed:@"thumbnail"];

    [self.navigationController pushViewController:destinationViewController animated:YES];

    [destinationViewController release];
}

输出是:

2012-07-20 10:43:29.976 jsonimage2[682:f803] 5 - fifth activity -http://i1184.photobucket.com/albums/z328/iElmoTutorials/CrazyEye.png
2012-07-20 10:43:31.878 jsonimage2[682:f803]  The button's image is <UIImage: 0x6aa16c0>.
2012-07-20 10:43:33.846 jsonimage2[682:f803] it works
2012-07-20 10:43:33.861 jsonimage2[682:f803] -[ViewController setImg:]:  unrecognized selector sent to instance 0x68a8b80
4

3 回答 3

0

从文档中,instantiateViewControllerWithIdentifier:返回一个__kindof UIViewController *.

您的代码将其归因于 a DestinationViewController *,但实际上它是ViewController *根据崩溃日志返回的。"Destination"所以你可能忘记在情节提要中正确设置类。

于 2019-07-07T15:16:04.190 回答
-1

设置的destinationViewController.img行将触发对 的隐式调用setImg:

我看不到 of 的定义,DestinationViewController但它显然不包含该img属性的定义。您可以通过添加适当@property的 forimg或通过实现setImg:andimg方法来实现这一点。

于 2012-07-20T05:33:54.787 回答
-1

你应该在@implementation DestinationViewController 之后忘记@synthesize img

于 2012-07-20T05:58:21.427 回答