假设我的 ViewController 中有一个非常简单的方法,它返回一个数字。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Number: %i",self.returnNumber);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)returnNumber
{
NSInteger number = 2;
return number;
}
@end
这工作得很好,但是当我修改方法 returnNumber 以接受这样的输入参数时:
#import "ViewController.h"
@interface ViewController (
)
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Number: %i",self.returnNumber:2);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)returnNumber:(NSInteger)insertedNumber
{
NSInteger number = insertedNumber;
return number;
}
@end
编译器说:
在“ViewController *”类型的对象上找不到属性“returnNumber”
是某种错误还是我完全没有了解 Objective-C 方法的工作原理?