gpt4 book ai didi

ios - 从xcode中的同一类调用方法

转载 作者:行者123 更新时间:2023-12-01 18:12:22 25 4
gpt4 key购买 nike

我想调用方法“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...

}

关于ios - 从xcode中的同一类调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28039531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com