Ios 在xcode中从同一类调用方法

Ios 在xcode中从同一类调用方法,ios,objective-c,xcode6,Ios,Objective C,Xcode6,我想调用一个方法“shows()”,但为什么会出现“预期标识符”或“和“使用未声明的标识符self”的错误 ViewController.m #import <UIKit/UIKit.h> @interface ViewController : UIViewController { NSDictionary *inventory; } - (void)shows; @end #import "ViewController.h" @interface ViewContro

我想调用一个方法“shows()”,但为什么会出现“预期标识符”或“和“使用未声明的标识符self”的错误

ViewController.m

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    NSDictionary *inventory;
}
- (void)shows;
@end
#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

您必须将代码放在另一个方法中,不能让它自己处于打开状态


把它放在你的
viewdiload:
方法或其他地方

你必须把代码放在另一个方法中,不能让它自己打开


将它放在你的
viewDidLoad:
方法或其他地方

你不能在外部调用此方法。你可以在任何其他方法内部调用它。就像你可以在
viewDidLoad
中调用此方法一样

 - (void)viewDidLoad { 
       [super viewDidLoad];    
       [self shows];   
 }

您不能在外部调用此方法。您可以在任何其他方法内部调用它。就像您可以在
ViewDidLoad
中调用此方法一样

 - (void)viewDidLoad { 
       [super viewDidLoad];    
       [self shows];   
 }

您不能在类范围内调用
[view shows];
,您需要在方法内调用它,如在
viewdiload
可以这样称呼:

- (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...

}

您不能在类范围内调用
[view shows];
,您需要在方法内调用它,如在
viewdiload
可以这样称呼:

- (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...

}

这是错误调用[self shows]的屏幕截图;在我不理解的任何一种方法中。我必须创建另一种方法?你的调用方法在函数外,在viewdidload中调用或在Brasses中使用的任何其他方法这里是错误调用[self shows]的屏幕截图;在任何一个我不理解的方法中。我必须创建另一个方法?在函数外调用方法,在viewdidload中调用或在brasses中使用的任何其他方法