【问题标题】:Method not being called方法没有被调用
【发布时间】:2012-03-13 03:17:36
【问题描述】:

我在一个单独的文件中的一个类中有一个相当简单的方法,它接受一个整数,在 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 对象,我希望将返回的值存储在其中。其次,根本没有调用该方法的原因是什么?我真的被难住了,但我敢肯定这非常简单。

谢谢,提前!

【问题讨论】:

  • 你能显示名称为 sceneChanger 的对象的头文件吗?该对象应该是方法 changeSceneURL: 所在的位置。但是可能会发生其他事情,因此将整个头文件添加到您的原始问题中。
  • nextURL=行下断点,查看sceneChanger的值。它可能为零。

标签: objective-c methods xcode4.2 call nsurl


【解决方案1】:

检查sceneChanger 不是nil。您可以向nil 发送消息,但不会调用该方法。

编辑你应该像这样初始化sceneChanger

sceneChanger = [[ChangeCurrentScene alloc] init];

【讨论】:

  • 是的,它是零。我在 gdb 中使用“po sceneChanger”进行了测试。如何为其赋值?我需要为它分配一个 NSURL 还是一个 int?它是一种方法,我不知道方法具有价值。
  • @lukech - 不,sceneChanger 是一个对象,它是ChangeCurrentScene 的一个实例。
猜你喜欢
  • 2014-06-02
  • 2011-08-28
  • 2017-02-24
  • 2015-02-23
  • 2013-12-19
  • 1970-01-01
  • 2020-09-19
  • 1970-01-01
相关资源
最近更新 更多