【问题标题】:Xcode for How to call function from one class to another class function in iPhone AppsXcode for How to call function from a class to another class function in iPhone Apps
【发布时间】:2012-01-10 06:07:02
【问题描述】:

JewelsSharedController.m:

-(void)GetCountries:(id)sender detailDictionary:(id)details
{
}

我想在RootViewController的函数中调用这个函数
RootController.m:

-(void)soapresult
{
    //i want to call ""GetContries "" here..
}

我把这个"soapresult"叫到

-(void)viewdidLoad
{
    [self soapresult];
}

但是调用函数时会崩溃

【问题讨论】:

  • 请在代码“崩溃”的问题中包含崩溃日志或消息。光靠这个词是没有用的。

标签: objective-c ios xcode ios4 xcode4


【解决方案1】:

JewelsSharedController.h:

//...
-(void)GetCountries:(id)sender detailDictionary:(id)details;
//...

RootController.m:

#import "JewelsSharedController.h"

//...

-(void)soapresult
{
    JewelsSharedController * jewelsSharedController = [[JewelsSharedController alloc] init];
    [jewelsSharedController GetCountries:yourSender detailDictionary:yourDetails];
    [jewelsSharedController release];
}

【讨论】:

    【解决方案2】:

    改变这个

    -(void)GetCountries:(id)sender detailDictionary:(id)details
    

    {

    }

    到

    +(void)GetCountries:(id)sender detailDictionary:(id)details
    

    {

    }

    然后在另一个类中调用它就可以了

    [JewelsSharedController GetCountries];
    

    我们正在做的是创建一个类函数,这意味着您可以直接在类上调用该函数,而无需先初始化该类的实例。

    【讨论】:

      猜你喜欢
      • 2022-12-01
      • 2022-12-01
      • 2022-12-02
      • 2022-11-20
      • 2022-12-01
      • 2022-07-31
      • 1970-01-01
      • 2022-12-27
      • 2022-12-27
      相关资源
      最近更新 更多