【问题标题】:Can't call a method from another class using object无法使用对象从另一个类调用方法
【发布时间】:2014-07-19 19:58:52
【问题描述】:

我正在尝试使用对象从另一个类调用方法。没有警告或错误,但没有进行调用。执行未转移到指定的方法。

@interface ePub : NSObject 
- (void) paginateChapters;

@implementation ePub 

- (void) paginateChapters;
{
     for (int i=0; i<chapterLinks.count; i++)
     {
        [self splitAttributedStringToPages:[chapterFiles objectAtIndex:i] withChapter:[chaptersAsAttributedStringArray objectAtIndex:i]];
     }
}

然后我尝试使用它的对象调用

@interface ePubRootViewController : UIViewController 
{
  ePub *loadedEpub;
}

@implementation ePubRootViewController 
-(void) viewDidLoad()
{
   loadedEpub = [[ePub alloc]init];
}

-(void)releaseData
{
    loadedEpub=nil;
}

 -(void)changeFontSize:(id)sender
{
          [self releaseData];
          [loadedEpub paginateChapters];
}

【问题讨论】:

  • 这段代码应该运行 NSLog。你还在做什么?发布您的其余代码。
  • @CrimsonChris 但它不起作用。我设置断点 & 执行根本没有移动到方法
  • 那么你没有共享的代码有问题。
  • @CrimsonChris 还需要什么?我可以知道吗
  • 我尝试了相同的代码,它对我来说工作正常。 getProperties 中的日志正在控制台中打印。能不能试着编译一下。

标签: objective-c class object ios7 methods


【解决方案1】:

当你调用它的方法时,你的loadedEPub 对象为nil。您必须在对象响应方法调用之前对其进行初始化。

【讨论】:

  • 好的,非常感谢!!!我已经在 viewDidLoad() 中对其进行了初始化。但是在调用 changeFontSize() 方法之前,它在另一个方法中被设为 Nil。我没查过
猜你喜欢
  • 1970-01-01
  • 2012-04-30
  • 2013-04-21
  • 2012-10-04
  • 1970-01-01
  • 2013-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多