【问题标题】:ARC error: receiver type for instance message does not declare a method with selectorARC 错误:例如消息的接收器类型未使用选择器声明方法
【发布时间】:2012-01-02 12:26:01
【问题描述】:

我遇到了这个我无法弄清楚的错误。

错误:自动引用计数问题:接收器类型“pageAppViewController”例如消息未声明带有选择器“createContentPages”的方法

我在下面发布了我的代码。我的班级pageAppViewController 中确实有一个名为createContentPages 的方法。这是什么意思,是什么原因造成的?

//  contentViewController.m

#import "contentViewController.h"
#import "pageAppViewController.h"

@implementation contentViewController

@synthesize theImageView, dataObject;
@synthesize image;

- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

//error occurs on this next line    
pageAppViewController *newContent = [[pageAppViewController alloc] init];
self.image = [newContent createContentPages];
[self.theImageView setImage:  ((pageAppViewController *) [self.image objectAtIndex:0]) .images];


}

error: Automatic Reference Counting Issue: Receiver type 'pageAppViewController' for instance message does not declare a method with selector 'createContentPages'


//
//  pageAppViewController.m

#import "pageAppViewController.h"

@implementation pageAppViewController
@synthesize pageController;

@synthesize bookContent;

@synthesize images;


- (NSArray *) createContentPages
{

    UIImage *zero = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"TitlePage.png"]];
    UIImage *one = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"Page1.png"]];
    UIImage *two = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"Page2.png"]];
    UIImage *three = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"Page3.png"]];
    UIImage *four = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"Page4.png"]];
    UIImage *five = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"Page5.png"]];

    NSMutableArray *pageContent = [[NSMutableArray alloc] init];


    for (int i = 1; i < 7; i++)
    {
    pageAppViewController *content = [[pageAppViewController alloc] init];

    if (i == 1)
    {
        content.images = zero;
        [pageContent addObject:content];

         }

    else if (i == 2)
    {
        content.images = one;
       [pageContent addObject:content];
    }

    else if (i == 3)
    {
        content.images = two;   
        [pageContent addObject:content];
    }

    else if (i == 4)
    {
        content.images = three;
        [pageContent addObject:content];
    }

    else if (i == 5)
    {
        content.images = four;
        [pageContent addObject:content];
    }

    else if (i == 6)
    {
        content.images = five;
        [pageContent addObject:content];
    }
    }

     bookContent = [[NSArray alloc] initWithArray: pageContent];

    return bookContent;

}

【问题讨论】:

  • 你也应该在这里显示你的@interface。

标签: iphone objective-c ios ios5 automatic-ref-counting


【解决方案1】:

你有吗

- (NSArray *) createContentPages;

Controller的.h文件中的方法声明?

【讨论】:

  • 我没有那个声明。我刚刚添加了它并且它有效。非常感谢!!
  • 我的一位同事拥有更新版本的 LLVM,并且该消息不再出现。我不记得是哪一个,但似乎他们已经消除了在 @interface 中声明方法的需要,因为它们的定义和使用仅限于 @implementation
  • 是的,新的 LLVM 版本更加用户友好和容错。但是用一些 cmets 在 @interface 块中声明你的方法总是一个好主意。
  • 但是如果我们不想将它添加到头文件中怎么办,没有ARC是可能的,为什么不使用ARC
  • 但它在 .m 文件中的“私有”标头声明中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多