没有可见的@interface for方法声明选择器

时间:2015-01-24 14:10:16

标签: ios objective-c xcode

我正在尝试编写一个应用程序,该应用程序从名为Jan Kowalski的联系人处获取照片并在屏幕上显示。 我是iOS和xCode的新手,因此我的代码出错了。

这是我的.m文件

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

//@synthesize labelNewImage;
@synthesize labelOldImage;
//@synthesize imageViewNew;
@synthesize imageViewOld;



- (void) changePositionOfView:(UIView *)paramView to:(CGFloat)paramY
{

    CGRect viewFrame = paramView.frame;
    viewFrame.origin.y = paramY;
    paramView.frame = viewFrame;
}


- (void) createLabelAndImageViewForOldImage
{
    self.labelOldImage = [[UILabel alloc] initWithFrame:CGRectZero];
    self.labelOldImage.text = @"Obraz";
    self.labelOldImage.font = [UIFont systemFontOfSize:16.0f];
    [self.labelOldImage sizeToFit];
    self.labelOldImage.center = self.view.center;
    [self.view addSubview:self.labelOldImage];
    [self changeYPositionOfView:[self.labelOldImage
                                 to:80.0f]];// error - no visible @interface for 'UILabel' that declares the selector to

 self.imageViewOld = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
 self.imageViewOld.center = self.view.center;
 self.imageViewOld.contentMode = UIViewContentModeScaleAspectFit;
 [self.view addSubview:self.imageViewOld];
    [self changeYPositionOfView:[self.imageViewOld to:105.0f]];

}


- (ABRecordRef)getPersonWithFirstName:(NSString *)paramFirstName
                             lastName:(NSString *)paramLastName
                         inAddressBook:(ABRecordRef)paramAddressBook
{
    ABRecordRef result = NULL;
    if (paramAddressBook == NULL) {
        NSLog(@"Ksiazka ma wartosc NULL");
        return NULL;

    }

    NSArray *allPeople = (__bridge_transfer NSArray *)
    ABAddressBookCopyArrayOfAllPeople(paramAddressBook);
    NSUInteger peopleCounter = 0;
    for (peopleCounter=0; peopleCounter < [allPeople count]; peopleCounter++) {
        ABRecordRef person = (__bridge ABRecordRef)
        [allPeople objectAtIndex:peopleCounter];
        NSString *firstName = (__bridge_transfer NSString *)
        ABRecordCopyValue(person, kABPersonFirstNameProperty);
        NSString *lastName = (__bridge_transfer NSString *)
        ABRecordCopyValue(person, kABPersonLastNameProperty);

        BOOL firstNameIsEqual = NO;
        BOOL lastNameIsEqual = NO;

        if ([firstName length] == 0 && [paramFirstName length] == 0)
        {
            firstNameIsEqual = YES;

        }
        else if ([firstName isEqualToString:paramFirstName])
        {
            firstNameIsEqual = YES;
        }

        if ([lastName length] == 0 && [paramLastName length] == 0)
        {
            lastNameIsEqual = YES;

        }
        else if ([lastName isEqualToString:paramLastName])
        {
            lastNameIsEqual = YES;
        }
        if (firstNameIsEqual && lastNameIsEqual) {
            return person;

        }
    }
        return result;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor   = [UIColor blackColor];
    [self createLabelAndImageViewForOldImage];
    ABAddressBookRef addressBook = ABAddressBookCreate();

    if (addressBook !=NULL) {
        ABRecordRef janKowalski = [self getPersonWithFirstName:@"Jan" lastName:@"Kowalski" inAddressBook:addressBook];

        if (janKowalski == NULL) {
            NSLog(@"Nie znaleziono kontaktu tworzenie nowego.");
            janKowalski = [self newPersonWithFirstName:@"Jan" // error - no visible @interface for 'ViewController' that declares the selector 'newPersonWithFirstName

                                              lastName:@"Kowalski"
                                         inAddressBook:addressBook];

        }

        if (janKowalski == NULL) {
            NSLog(@"Nie udało się utworzyć nowego rekordu dla tego kontaktu.");
            CFRelease(addressBook);
            return;

        }

    self.imageViewOld.image = [[self getPersonImage]:janKowalski]; // error - no visible @interface for 'ViewController' delcares the selector 'getPersonImage'
    }
}

和我的.h文件:

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>



@interface ViewController : UIViewController

@property (strong, nonatomic) UILabel *labelOldImage;

@property (strong, nonatomic) UIImageView *imageViewOld;


@end

我得到这些“没有可见的@interface for'UILabel',它将选择器声明为”错误。 你们能不能以正确的方式让我如何解决这个问题?

非常感谢你!

2 个答案:

答案 0 :(得分:2)

放置方括号实际上只是一个错误。您已经使用两个参数定义了一个方法......

changePositionOfView:(UIView *)paramView to:(CGFloat)paramY

...但你只用一个人来称呼它......

[self changeYPositionOfView:[self.labelOldImage to:80.0f]];

检查括号的匹配。

编译器认为您要调用[self.labelOldImage to:80.0f]并将结果传递给名为changeYPositionOfView:的单参数方法。

通过修复嵌套将值传递给两个参数:

[self changeYPositionOfView:self.labelOldImage to:80.0f];

答案 1 :(得分:1)

问题:

- changePositionOfView:(UIView *)paramView to:(CGFloat)paramY

但是你发送了这个:

[self changeYPositionOfView:[self.labelOldImage
                                 to:80.0f]];// error - no visible @interface for 'UILabel' that declares the selector to

用2个参数制作它。

是的,当您使用@synthesize时,请使用labelOldImager调用标签/图片,而不是self.labelOldImage