助けてください、私は絶望的です..次の理由でアプリを続行できません:
私は 2 つのココア Objective-C クラスの間に 1 つのメッセージをセットアップしました。メインの appdelegate は NSNotificationCenter を介してビューにメッセージを送信しています。ビューは実際に通知を受け取りますが、どういうわけかビューに表示されているコントロールを更新できません。適切なインスタンスまたは何かが見つかりません。
これが私のコードです: mainapp ( appdelegate が私のビューにメッセージを送る場所):
helloKey = @"0";
helloString = @"mymessage";
values = [NSMutableDictionary dictionaryWithObject:helloString forKey:helloKey];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NewMessageNotification" object:self userInfo:values];
関数は myuiviewcontoler で定義されています
- (void)NewMessageNotification:(NSNotification *)notification
{
// key associated with string "Hello String"
helloKey = @"0";
// [notificaiton userInfo] returns "values"
helloFromMain = [[notification userInfo] objectForKey:helloKey];
NSLog(@"newmess=%@",helloFromMain; //this outputs mymessage , perfect right?? not quite..here's the problem
//then if I'm trying to update something visible ..it won't do IT!!!! :( :(
//tested with the debugger and it reaches this line...when the messaging occurs
[self.mybutton setTitle:@"sdsdsdasd" forState:UIControlStateNormal];
//this won't work, not it will give an error!!!
}
では、何が問題なのだろうか?これを使用する場合、目に見えるものはプログラムで変更できません。私はそれが必要です..
IBAction を実行し、それをこのビューのボタンに割り当てて同じことを行うと: [self.mybutton setTitle:@"sdsdsdasd" forState:UIControlStateNormal]; 問題なく表示が更新されます...タイトルを変更します...
では、NSnotificationcenter によって呼び出される関数と同じビューに属する関数の違いは何ですか...
どちらの場合も自己変数のアドレスを確認しようとしましたが、結果は同じです...だから..基本的に同じポインタを使用していますか?
それでもうまくいかない…
数日前に別の投稿を戻しました..しかし、誰も答え ません プログラムで作成されたラベルと画像が画面に表示されません