我正在关注“ Sams Teach Yourself iOS 6”,并且我尝试对此错误进行故障排除,但未成功。

这是我的ViewController.h文件:

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UISegmentedControl *colorChoice;
@property (weak, nonatomic) IBOutlet UIWebView *flowerView;
@property (weak, nonatomic) IBOutlet UIWebView *flowerDetailView;

- (IBAction)toggleFlowerDetail:(id)sender;
- (IBAction)getFlower:(id)sender;

@end


我得到的错误是在ViewController.m文件的此行[self.getFlower:nil];上:

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.flowerDetailView.hidden=YES;
    [self.getFlower:nil];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)toggleFlowerDetail:(id)sender {
        self.flowerDetailView.hidden=! [sender isOn];
}

- (IBAction)getFlower:(id)sender {
    NSURL *imageURL;
    NSURL *detailURL;
    NSString *imageURLString;
    NSString *detailURLString;
    NSString *color;
    int sessionID;

    color=[ self.colorChoice titleForSegmentAtIndex:self.colorChoice.selectedSegmentIndex];

    sessionID=random() % 50000;

    imageURLString=[[NSString alloc] initWithFormat: @"http://www.floraphotographs.com/showrandomios.php?color=%@&session=%d", color, sessionID];

    detailURLString=[[NSString alloc] initWithFormat: @"http://floraphotographs.com/detailios.php?session=%d", sessionID];

    imageURL=[[NSURL alloc]initWithString:imageURLString];
    detailURL=[[NSURL alloc]initWithString:detailURLString];

    [self.flowerView loadRequest: [NSURLRequest requestWithURL:imageURL]];
    [self.flowerDetailView loadRequest:[NSURLRequest requestWithURL:detailURL]];
    self.flowerDetailView.backgroundColor=[UIColor clearColor];
}

@end


方法getFlower已在头文件中声明,所以为什么不能在实现文件中使用它?

最佳答案

这个:

[self.getFlower:nil];


应该:

[self getFlower:nil];


这是一种方法,而不是属性。

关于ios - 正在获取:在“ViewController *”类型的对象上找不到属性“getFlower”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23258285/

10-11 14:48