2012-02-22 85 views
1

我在一个单独的文件中的类中有一个相当简单的方法,它接受一个整数,在一个case select中查找它,并返回一个对应于它的NSURL指针。它有以下方法:方法不被调用

#import <Foundation/Foundation.h> 

@interface ChangeCurrentScene : NSObject 
{ 
    NSString *filePath; 
    NSURL *url; 
    int currentScene; 
} 

- (NSURL *)changeSceneURL:(int)toDesiredScene; 

@end 

我不知道100%如何,我应该从外部调用它,但我有一个按钮,在我的故事板,这肯定工程挂钩,和我使用这条线把它称为:

nextURL = [sceneChanger changeSceneURL:1]; 

从这个头文件:

@interface MSViewController : UIViewController <AVAudioPlayerDelegate> { 

    BOOL userInputAvailable; 
    int currentScene; 
    NSURL *nextURL; 
    ChangeCurrentScene *sceneChanger; 

} 

@property (strong) AVAudioPlayer *menuPlayer; 
@property (strong, nonatomic) IBOutlet UILabel *userChoiceLabel; 
@property (strong, nonatomic) IBOutlet UIImageView *nowPlayingIcon; 


- (BOOL) playScene : (NSURL *)fileToBePlayed; 

@end 

我把一个断点在changeSceneURL的第一行:toDesiredScene类,但它不叫的。没有崩溃,但没有电话。首先,这是使用被调用方法返回的正确方法吗? nextURL是一个NSURL对象,我希望将返回的值存储在其中。其次,该方法根本不会被调用的原因是什么?我真的很难过,但我确信这是一件非常简单的事情。

谢谢,提前!

+0

您可以显示名为sceneChanger对象的头文件?该对象应该是方法changeSceneURL:所在的位置。但其他事情可能会发生,所以将整个头文件添加到您的原始问题。 – Jim 2012-02-22 18:37:32

+1

在'nextURL ='行放置一个断点,并检查sceneChanger的值。它可能是零。 – jrturton 2012-02-22 18:37:46

回答

1

Chech sceneChanger不是nil。您可以将消息发送到nil,但该方法不会被调用。

编辑你应该某处初始化sceneChanger这样的:

sceneChanger = [[ChangeCurrentScene alloc] init]; 
+0

是的,它是零。我在gdb中用“po sceneChanger”进行了测试。我如何为它分配一个值?我需要为它分配一个NSURL还是一个​​int?这是一种方法,我不知道一种方法有价值。 – Luke 2012-02-22 18:47:07

+0

@lukech - 不,“sceneChanger”是一个对象,它是“ChangeCurrentScene”的一个实例。 – sch 2012-02-22 18:49:30