あなたは新しいcategoryMapのビューのcontrolerオブジェクトを作成していて、そのラベルではなく、現在されているcategoryMapビューコントローラから1を更新しています表示されます。 "NSObject"インスタンスは、実際に画面に表示されるViewControllerを指し示すreflen-rence(プロパティ)を必要とします。
-(void)getCategoryId:(NSString *)categoryid {
// View controller is created
categoryMap *catMap = [[categoryMap alloc] init];
// label updated
[catMap getCategoryId:categoryid];
catMap.nePOI = categoryid;
// End of the method, View controller is destroyed
// See the problem here??? You are not updated the good viewController...
}
これはおすすめの方法ではありませんが、あなたのviewControllerは、何を表示するかをオブジェクトに尋ねる必要があります。しかし、あなたの場合、通知でこれを修正することができます。
[[NSNotificationCenter defaultCenter] postNotificationWithName:@"categorySelected" object:categoryId];
によってオブジェクトクラスで、あなたのビューのcontrolerでそれにviewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCategoryId:) name:@"categorySelected" object:nil];
を購読して、getCategoryIdを置き換えます:getCategoryIdの実装を交換し、あなたのビューコントローラの方法によって:
-(void)getCategoryId:(NSNotification *)notif {
self.label.text = (NSString *)(notif.object);
}
これはすべきです;;)
ViewControllerの原則の背後にあるアーキテクチャをよりよく理解するには、Apple MVCのドキュメントを参照してください。https://developer.apple.com/library/mac/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html
@TejaNandamuri問題の例を書きました。デフォルトでは、いくつかのガイドラインがあります。私は機能するようにローカルにアピールし、適切に動作します。 – Kejl
値が変更されると、デリゲート(プロトコル)を使用してデータを渡すことができます。また、NSNotificationCenterはそれを実行するための良いオプションです。 –