2012-02-23 39 views
0

我想從主視圖控制器中的NSDictionary中將變量加載到詳細視圖控制器中。使用UIImage作爲if語句中的條件

我想在主視圖控制器中使用圖像來確定在詳細視圖控制器中使用哪個變量。

我的代碼是這樣的在主視圖控制器;

-(IBAction)pushView:(id) sender{ 

    SomeDetailViewController *detailController = [[SomeDetailViewController alloc] init]; 


    if ((self.imageView.image = [UIImage imageNamed:@"0002.jpg"])) { 
     NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
               @"titleA", @"headerkey2",,nil]; 

     detailController.mapDictionary = mapDictionary; 

     NSLog(@"%@", [myDictionary objectForKey:@"headerkey2"]); 
    } 

    else if((self.imageView.image = [UIImage imageNamed:@"0003.jpg"])) { 
     NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
               @"TitleB", @"headerkey2",,nil]; 

     detailController.myDictionary = myDictionary; 

     NSLog(@"%@", [myDictionary objectForKey:@"headerkey2"]); 
    } 

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

               } 

然後在我的接收細節視圖控制器我的代碼;

-(void) viewDidLoad{ 
[super viewDidLoad]; 

self.title = [(NSMutableDictionary *)myDictionary objectForKey:@"headerkey2"]; 

} 

不幸的是,這是行不通的。無論如何,導航條標題都會顯示相同的內容。

我可以使用UIImage作爲條件嗎?

任何幫助將不勝感激。

我已經使用了反彈,但似乎並沒有在所有情況下工作。

回答

0

由於某種原因你在if語句中使用「=」嗎?如果不是,請改用「==」。

該文檔說[UIImage imageNamed]返回與指定圖像關聯的對象,這意味着它應該始終爲同一圖像返回相同的對象,因此您可以在條件中使用UIImage。

+0

非常感謝你。 – user1114881 2012-02-23 18:13:47

+0

@ user1114881可否請您檢查我的答案是否接受,如果它的作品?我會很感激。 – hago 2012-02-28 17:03:48