2012-02-20 3 views
0

私は、detailViewControllerを画面にプッシュするmainViewControllerを持っています。 detailViewControllerの項目(画像、ナビゲーションバーのタイトル、テキストビュー、およびボタン)は、どの画像がタップされているかに応じて、MainViewControllerのNSMutableDictionaryからすべてロードされます。ナビゲーションバーのタイトルから辞書をロードする

また、detailViewControllerにボタンがあり、選択するとユーザーの場所を示すマップビューが読み込まれます。ユーザがボタンをタップすると、注釈吹き出しタイトルを用いてピンを落としてこの位置をマークする。

MainViewControllerのNSMutableDictionaryからロードされたdetailViewControllerのものと同じになるように、mapviewのタイトルと注釈のタイトルが必要です。

今、mapviewのタイトルと注釈のタイトルの決定要因としてdetailViewControllerのタイトルを使用しようとしています。しかし、これは動作していません。

ここにMainViewController .mのコードを示します。

- (void) coverflowView:(TKCoverflowView*)coverflowView coverAtIndexWasDoubleTapped:(int)index{ 

    SomeDetailViewController *detailViewController = [[SomeDetailViewController alloc] initWithNibName:@"SomeDetailViewController" bundle:nil]; 

    if ((int)index == 0) { 
     NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
         @"0002.jpg", @"imagekey", 
         @"This is tree 0002", @"textkey", 
         @"0002.image.png",@"imagekey2", 
         @"0002 title", @"headerkey", 
         @"www.0003.com", @"address",nil]; 

     NSLog(@"%@", [myDictionary objectForKey:@"imagekey"]); 
     NSLog(@"%@", [myDictionary objectForKey:@"textkey"]); 
     NSLog(@"%@", [myDictionary objectForKey:@"imagekey2"]); 
     NSLog(@"%@", [myDictionary objectForKey:@"address"]); 
     NSLog(@"%@", [myDictionary objectForKey:@"headerkey"]); 
     detailViewController.myDictionary = myDictionary; 
    } 

    else if ((int)index == 1) { 
     NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
              @"0003.jpg", @"imagekey", 
              @"This is 0003", @"textkey", 
              @"0003.image.png",@"imagekey2", 
              @"0003 title", @"headerkey", 
              @"www.0003.com", @"address",nil]; 

     NSLog(@"%@", [myDictionary objectForKey:@"imagekey"]); 
     NSLog(@"%@", [myDictionary objectForKey:@"textkey"]); 
     NSLog(@"%@", [myDictionary objectForKey:@"imagekey2"]); 
     NSLog(@"%@", [myDictionary objectForKey:@"address"]); 
     NSLog(@"%@", [myDictionary objectForKey:@"headerkey"]); 
     detailViewController.myDictionary = myDictionary; 
    } 

    [self.navigationController pushViewController:detailViewController animated:YES]; 
} 

ここはdetailViewController.mのコードです。 これは、辞書の文字列をロードします(太字の部分はナビゲーションバーのタイトルをロードしています)。私は決定要因として、現在のナビゲーションバーのタイトルを使用して、ナビゲーションバーのタイトルと注釈のタイトルをロードしようとしていますのはここ

- (void)viewDidLoad { 
    NSString *filePath =[self pathOfFile]; 
    if ([[NSFileManager defaultManager]fileExistsAtPath:filePath]){ 
     NSArray *array = [[NSArray alloc]initWithContentsOfFile:filePath]; 
     myText.text = [array objectAtIndex:0]; 
    } 

    UIApplication *app = [UIApplication sharedApplication]; 
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app]; 
    [super viewDidLoad]; 

    imageView .image = [[UIImage alloc] init]; 
    self.imageView.image =[UIImage imageNamed:[(NSMutableDictionary *)myDictionary objectForKey:@"imagekey"]]; 

    imageView2 .image = [[UIImage alloc] init]; 
    self.imageView2.image =[UIImage imageNamed:[(NSMutableDictionary *)myDictionary objectForKey:@"imagekey2"]]; 

    self.myText.text =[(NSMutableDictionary *)myDictionary objectForKey:@"textkey"]; 

    **self.navigationItem.title = [(NSMutableDictionary *)myDictionary objectForKey:@"headerkey"];** 
    NSLog(@"%@", [myDictionary objectForKey:@"imagekey"]); 
    NSLog(@"%@", [myDictionary objectForKey:@"imagekey2"]); 
    NSLog(@"%@", [myDictionary objectForKey:@"textkey"]); 
    NSLog(@"%@", [myDictionary objectForKey:@"headerkey"]); 
} 

です。 これは、安定した要素がないので、私が考えることができる唯一のものです。 detailViewControllerのすべてがMainViewController NSDictionaryからロードされます。

-(IBAction)pushMap:(id) sender{ 

    SomePositionViewController *somePosition = [[SomePositionViewController alloc] init]; 


    if ((self.navigationItem.title = @"0002 title")) { 
     NSMutableDictionary *mapDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
               @"0002a title", @"headerkey2", 
              @"0002 annotation title", @"titlekey",nil]; 
     treePosition.mapDictionary = mapDictionary; 
     NSLog(@"%@", [mapDictionary objectForKey:@"titlekey"]); 
     NSLog(@"%@", [mapDictionary objectForKey:@"headerkey2"]); 
    } 

    else if((self.navigationItem.title = @"0003 title")) { 
     NSMutableDictionary *mapDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
               @"0003a title", @"headerkey2", 
               @"0003 annotation title", @"titlekey",nil]; 
     treePosition.mapDictionary = mapDictionary; 
     NSLog(@"%@", [mapDictionary objectForKey:@"titlekey"]); 
     NSLog(@"%@", [mapDictionary objectForKey:@"headerkey2"]); 
    } 

    [self.navigationController pushViewController:somePosition animated:YES];  

               } 

これをどのように達成することができますか?私は自分の脳を壊しているが役に立たない。助けて!

+0

これが問題であるかどうかはわかりませんが、pushMapメソッドで 'if((self.navigationItem.title = @" 0002タイトル "))'が間違っています。まず、単一の '= '記号が代入を行います。二重 '=='は等価性をチェックするためのものです。次に、_NSString_等価性をチェックするには、isEqualToString:を使用する必要があります(例えば、if([self.navigationItem.title isEqualToString:@ "0002タイトル"]))。 – Anna

答えて

0

私が見つけたことの1つは、文字列を間違った方法で比較していることです。あなたは

if ((self.navigationItem.title = @"0002 title")) 

を使用するが、常に失敗するあなたの方法で文字列を比較

if (([self.navigationItem.title isEqualToString:@"0002 title"])) 

使用する必要があります。

+0

申し訳ありません、これを試しても機能しません。私は何らかの理由で、タイトルを変数として使用しても動作しないと思います。その他の提案はありますか? – user1114881

+0

私は2つの提案があります。まず、コード内にブレークポイントを設定し、変数に実際に含まれているものを調べます。あなたは何がうまくいかないかを知ることができます。次に、詳細ビューにデータを提供するより一般的な方法を使用します。詳細ビュー(「placeTitle」など)でインスタンス変数を作成し、親ビューで詳細ビューを作成するときは、そうである。ナビゲーション項目のタイトルを使用しようとすると効果がありますが、これを行うには奇妙な方法です。 –

関連する問題