0

私はクラスA(テーブルビューコントローラー)の関数にいて、クラスB(UserDetailsクラス)​​のオブジェクトがあります。次のようなものです:

-(void) connectionFinishedLoading:(NSURLConnection*) connection :(UserDetails *) user{

//some code
user=A;
}

クラスC(テーブルビューコントローラー)の関数(クラスA関数とは異なる)で「ユーザー」オブジェクトの値を使用したい。

 -(void)newfunction :(NSURLConnection*) connection{
 //I want to use the value of "user" here.
  }

ありがとう。

4

2 に答える 2

1

さまざまなクラスで使用する必要があるオブジェクトを、Singleton などの共有プレースホルダー クラスに格納します。次に、その共有インスタンスを取得して、必要なオブジェクトを取得します。パターンを取得するために少しグーグルしてください。

于 2012-09-26T11:41:15.343 に答える
0

値を保存してさまざまなクラスで使用する最善の方法は、appDelegate クラスのプロパティを使用することです。

appDelegate クラスにプロパティを作成し、NSString *user; と言います。それを合成する

connectionDidFinishLoading のように AppDelegate のインスタンスを作成します

YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication]delegate];
appDelegate.user = A;

さらに

-(void)newfunction :(NSURLConnection*) connection{
 //I want to use the value of "user" here.
    YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication]delegate];
NSLog(@"%@",appDelegate.user);
  }
于 2012-09-26T11:45:12.483 に答える