没有调用Objective-C方法

时间:2021-01-12 22:52:14

It's either because of the fact I'm tired or because I'm doing it wrong, but for some reason I can't get it to call a method.

这要么是因为我累了,要么是因为我做错了,但由于某种原因我无法让它调用方法。

Here's what I'm trying to call:

这是我要打电话的内容:

-(void)newHighScore:(int)d

Which right now just does an NSLog saying "yea I'm working!"

现在只是NSLog说“我在工作!”

I'm calling it like this:

我这样称呼它:

[highscore newHighScore:score];

highscore is what I called the HighScore class in the .h, and score is an int with the score.

highscore是我在.h中称为HighScore类的,而得分是得分的int。

2 个解决方案

#1


15  

Did you initialize the highscore object?

你初始化高分对象了吗?

The newHighScore is an instance method, so it needs an instance of that object?

newHighScore是一个实例方法,所以它需要一个该对象的实例?

You should have, before you call the method, something along the lines of

在调用方法之前,你应该有类似的东西

HighScore *highscore = [[HighScore alloc] init];

Otherwise, highscore will be nil, and any messages passed to nil simply do nothing.

否则,highscore将为nil,并且传递给nil的任何消息都不会执行任何操作。

#2


2  

I'm guessing, and this is likely correct, that highscore is nil.

我猜,这可能是正确的,高分是零。

#1


15  

Did you initialize the highscore object?

你初始化高分对象了吗?

The newHighScore is an instance method, so it needs an instance of that object?

newHighScore是一个实例方法,所以它需要一个该对象的实例?

You should have, before you call the method, something along the lines of

在调用方法之前,你应该有类似的东西

HighScore *highscore = [[HighScore alloc] init];

Otherwise, highscore will be nil, and any messages passed to nil simply do nothing.

否则,highscore将为nil,并且传递给nil的任何消息都不会执行任何操作。

#2


2  

I'm guessing, and this is likely correct, that highscore is nil.

我猜,这可能是正确的,高分是零。