1

ApplicationDidEnterForeground新しいビューを割り当てずに、アプリのデリゲート メソッドからデータ (ラベル) を変更する必要があります。ビューは「リマインダー」と呼ばれるので、デリゲートにインポートし、割り当てた場合にのみそのデータにアクセスできます(リマインダー*何でも= [リマインダーの割り当て...など)が、現在読み込まれているビューを変更したいので既に読み込まれているビューに直接アクセスする必要があります。

アプリケーションがフォアグラウンドに入るとすぐにメイン ビューのラベルをデリゲートから変更するにはどうすればよいですか?

obs: できることはわかっていますが-(void)ViewDidLoad-(void)ViewWillAppear問題は解決しません。たとえば、ユーザーが通知ボックス (電話がロックされているときにスライド アイコン) からアプリを開いた場合、ラベルは変更されないためです。その場合、アプリがバックグラウンドで開いていた場合、上記のメソッドはいずれも呼び出されません。

私が明確だったかどうかはわかりませんが、そうであることを願っています。前もって感謝します。

4

3 に答える 3

1

ApplicationDidEnterForeground: メソッドから通知を送信し、ラベルを更新するクラスで受信するだけです...このように..

//Your ApplicationDidEnterForeground:
[[NSNotificationCenter defaultCenter] postNotificationWithName:@"UpdateLabel" withObject:nill];

ラベルを更新するコントローラーの viewDidLoad: にオブザーバーを追加します

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

同じクラスでメソッドを作成しました...

- (void)updateLabel:(NSNotification *)notification{
    update label
}
于 2012-06-29T08:07:19.613 に答える
1

ストーリーボードを使用している場合は、これを実行して、現在表示されているビューにアクセスできます

- (void)applicationDidEnterBackground:(UIApplication *)application
{ 
UINavigationController *a=_window.rootViewController;
Reminder *rem = a.topViewController;
rem.label.text=@"test";
}

ストーリーボードを使用しない場合

後でアクセスする必要があるビューを作成するときは、次のようにプロパティとして定義します。

AppDelegate.h で

//@interface SIMCAppDelegate : UIResponder <..........>
//{
//Some variables here
//}

//Properties here
@property (strong, nonatomic) Reminder *reminder;

//Some method declaration here
//eg: -(void) showSomething;

AppDelegate.m で

//@implementation AppDelegate

@synthesize reminder;

したがって、このようにビューを割り当て/初期化すると

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//codes before here

self.reminder = [[Reminder alloc] init];
self.reminder.label.text = @"OLD LABEL";
//codes after here
}

このように、他の方法で割り当てた後、再びアクセスできるようになります

- (void)applicationWillEnterForeground:(UIApplication *)application
{

self.reminder.label.text = @"NEW LABEL";
}
于 2012-06-29T08:27:27.623 に答える
0

次のコードを試すことができるかもしれません-

NSMutableArray *activeControllerArray =  [self.navigationController.viewControllers mutableCopy];
for (int i = 0; i< [activeControllerArray count]; i++) {
    if ([[activeControllerArray objectAtIndex:i] isKindOfClass:[Reminder Class]) {
        Reminder *object = [activeControllerArray objectAtIndex:i];

        //Perform all the task here which you want.

        break; //Once found break the loop to do further processing.
    }
}
于 2012-06-29T08:04:12.567 に答える