私は、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];
}
これをどのように達成することができますか?私は自分の脳を壊しているが役に立たない。助けて!
これが問題であるかどうかはわかりませんが、pushMapメソッドで 'if((self.navigationItem.title = @" 0002タイトル "))'が間違っています。まず、単一の '= '記号が代入を行います。二重 '=='は等価性をチェックするためのものです。次に、_NSString_等価性をチェックするには、isEqualToString:を使用する必要があります(例えば、if([self.navigationItem.title isEqualToString:@ "0002タイトル"]))。 – Anna