无法识别的选择器发送到实例

时间:2012-07-20 05:25:06

标签: iphone ios xcode

这是我的代码:

- (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

任何帮助?

提前致谢。

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

我看不到DestinationViewController的定义,但它显然不包含img属性的定义。您可以通过为@property添加适当的img或通过实施setImg:img方法来实现此目的。

答案 2 :(得分:0)

你应该在@implementation DestinationViewController

之后忘记@synthesize img
相关问题