繁体   English   中英

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

[英]No visible @interface for method declares the selector

我正在尝试编写一个应用程序,该应用程序从名为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',它将选择器声明为”错误。 你能不能让我以正确的方式解决这个问题?

非常感谢!

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

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

......但是你只用一个叫它......

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

检查括号的匹配。

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

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

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

问题:

- 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调用label / image labelOldImager ,而不是self.labelOldImage

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM