简体   繁体   中英

No visible @interface for method declares the selector

I'm trying to write an app that takes photo from contact named Jan Kowalski and shows on screen. I'm pretty new to iOS and xCode and so I got errors in my code.

Here's my .m file

#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'
    }
}

and my .h file:

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



@interface ViewController : UIViewController

@property (strong, nonatomic) UILabel *labelOldImage;

@property (strong, nonatomic) UIImageView *imageViewOld;


@end

I'm getting these "no visible @interface for 'UILabel' that declares the selector to" errors. Could you guys get me on the right way how to solve this problem?

Thank you so much!

It's really just an error in placing square brackets. You've defined a method with two parameters...

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

...but you're calling it with only one...

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

Check the matching of the brackets.

The compiler thinks you want to call [self.labelOldImage to:80.0f] and pass the result to a single-parameter method called just changeYPositionOfView: .

Pass values to both parameters by fixing the nesting:

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

The problem:

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

But you send this:

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

Make it with 2 params.

And yeah, when you use @synthesize, after that call label/image with labelOldImager , not self.labelOldImage .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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