我想调用方法“ shows()”,但是为什么我得到“期望的标识符或(和使用未声明的标识符自身”的错误信息
ViewController.m
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
NSDictionary *inventory;
}
- (void)shows;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
inventory = @{@"Rahul":[NSNumber numberWithInt:11],
@"iOS":[NSNumber numberWithInt:22]};
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)shows
{
NSLog(@"%@",inventory);
}
[self shows];
@end
您不能[view shows];
在类范围内调用,需要在一个方法中viewDidLoad
调用它,例如在“像这样调用它”中:
- (void)viewDidLoad {
[super viewDidLoad];
inventory = @{@"Rahul":[NSNumber numberWithInt:11],
@"iOS":[NSNumber numberWithInt:22]};
// Do any additional setup after loading the view, typically from a nib.
[self shows];//SHOWS call moved here...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句