Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gbenna

macrumors member
Original poster
Jul 27, 2011
62
0
I want to display a navigationBar title from a NSDictionary. In the firstDetailViewController I have a UIImageView which changes depending on the row selected in the pushing tableview controller.

I want to use these changing images to determining what the navigationBar title (among other things) will be in a secondDetailViewController which is pushed by the firstDetailViewController.

Here is my code for the firstDetailViewController;


Code:
-(IBAction)pushView:(id) sender{
    
    secondDetailViewController *secondDetail = [[secondDetailViewController alloc] init]; 
    
    
    if ((self.imageView.image = [UIImage imageNamed:@"0002.jpg"])) {
        NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                              @"TitleA", @"headerkey2", nil];
                                          
       secondDetail.myDictionary = myDictionary;
       
        NSLog(@"%@", [mapDictionary objectForKey:@"headerkey2"]);
    }
    
    else if((self.imageView.image = [UIImage imageNamed:@"0003.jpg"])) {
        NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                              @"TitleB", @"headerkey2",nil];
                                              
        secondDetail.myDictionary = myDictionary;
        
       NSLog(@"%@", [mapDictionary objectForKey:@"headerkey2"]);
    }

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

in my secondDetailViewController's viewDidLoad my code is;

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

This is not working, only the TitleA shows up no matter what.

Can I use a UIImage as a condition and if so what am I doing wrong.

Thanks for the help.
 
Last edited by a moderator:
1) Is = a comparison or assignment operator

2) Can you compare UIImage instances in this way? What makes you sure that a UIImage returned by imageNamed: is the same instance as one already in use? It might be due to caching. But perhaps it might not be (although the above is a more pressing error)
 
using uiimage in a if (condition) statement

You are right. I changed it to an == statement and now everything is working fine. Thanks.
 
1) Is = a comparison or assignment operator

2) Can you compare UIImage instances in this way? What makes you sure that a UIImage returned by imageNamed: is the same instance as one already in use? It might be due to caching. But perhaps it might not be (although the above is a more pressing error)

You are right. I changed it to an == statement and now everything is working fine. Thanks.

Alright, now that you've addressed issue #1, you should make sure you've addressed issue #2. Just because your code works fine now, doesn't necessarily mean it always will.
 
Using uiimage in a if (condition) statement

I have written several else if statements on this and it works fine. Thanks for all the help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.