1

こんにちは、これが簡単な答えであることを願っています。それは、私がこれに慣れていないからです。

別のクラス内から別のクラスに存在するビューを削除できるようにしようとしています。

クラスでは、これを行うメソッドを呼び出しています。

ViewController *viewController = [[ViewController alloc] init];
[viewController closeNotifiactions];

そして、私の他のクラスでは、ビューを削除しようとしているメソッドがあります。このメソッドに NSLog を配置すると、呼び出されて機能しますが、removeFromSuperview コードは機能しません。

-(void)closeNotifiactions
{
    [spinner removeFromSuperview];
    [loadingView removeFromSuperview];
}

私の .h ファイルでは、次のように closeNotifications メソッドを参照しています。-(void)closeNotifiactions;

closeNotifications 部分を機能させるために何か別のことをする必要がありますか? ありがとうございました!

4

2 に答える 2

0
ViewController *move = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];;
        [move closeNotifiactions];
        [move release];
于 2013-09-04T06:20:33.050 に答える
0

NSNotification を使用して、別のクラスに適切にアクセスできます。

クラスA:

//NSNotification を作成する

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeNotifiactions) name:@"notification" object:nil];

クラス B: //単に NSNotification を呼び出してそのメソッドを呼び出します

[[NSNotificationCenter defaultCenter] postNotificationName:@"notification" object:nil];

これがお役に立てば幸いです。

于 2013-09-04T06:13:18.157 に答える