![](/img/trans.png)
[英]No visible @interface for [object] declares the selector [method]
[英]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.