Kex
Kex

Reputation: 776

Populate UIView with UIVIewController in a Navigation Based App

I'm making a test application for listing movies in a Navigation Based Application using data from a plist file that I read in my appDelegate in the application:didFinishLaunchingWithOptions:. When I try to go to the second detailViewController I get the title partially changed (I get the title of the movie but instead of the year in the UIView.title I get something like "78898320" & empty UIImageView & UILabels. What am I missing?

Populated from my app rootViewController

Populated from my app detailViewController

Here is my method in the rootViewController:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath     *)indexPath
{
NSLog(@"YOU SELECTED: %d",indexPath.row);

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

NSDictionary *dict = [NSDictionary dictionaryWithDictionary:
                      [movies objectAtIndex:indexPath.row]];

[detailView fill:dict];

[self.navigationController pushViewController:detailView animated:YES];
[detailView release];

}

Here is my method for filling the UIView in the detailViewController:

-(void)fill: (NSDictionary*) fillData
{
//movie = [NSDictionary dictionaryWithDictionary:fillData];
NSLog(@"DETAILS: %@",[fillData objectForKey:@"description"]);

self.title = [NSString stringWithFormat:@"%@ (%d)",
              [fillData objectForKey:@"title"],
              [fillData objectForKey:@"year"]];
//[movie objectForKey:@"title"];
self.img = [[UIImageView alloc] initWithImage:
            [UIImage imageNamed:[fillData objectForKey:@"image"]]];
self.description = [fillData objectForKey:@"description"];
self.cast = [fillData objectForKey:@"cast"];
}

When I try to print the description from the dictionary using NSLog it prints out fine.

Upvotes: 0

Views: 282

Answers (3)

user756245
user756245

Reputation:

You will have to change some things to do it working. I guess all your labels and image views are actually in a NIB file.

By doing :

self.img = [[UIImageView alloc] initWithImage:
            [UIImage imageNamed:[fillData objectForKey:@"image"]]];

you are actually breaking the connection between the property and the object in the NIB file, by replacing it with a fresh new instance. Unless you add manually the new one to the view, nothing can appear.

Try using :

[self.img setImage:[UIImage imageNamed:[fillData objectForKey:@"image"]]];

The same applies to :

self.description = [fillData objectForKey:@"description"];
self.cast = [fillData objectForKey:@"cast"];

Try instead :

[self.description setText:[fillData objectForKey:@"description"]];
[self.cast setText:[fillData objectForKey:@"cast"]];

Upvotes: 1

Amit Singh
Amit Singh

Reputation: 8383

-(void)fill: (NSDictionary*) fillData
{
    //movie = [NSDictionary dictionaryWithDictionary:fillData];
    NSLog(@"DETAILS: %@",[fillData objectForKey:@"description"]);

    self.title = [NSString stringWithFormat:@"%@ (%d)",
          [fillData objectForKey:@"title"],
          [[fillData objectForKey:@"year"] intValue]];
    //[movie objectForKey:@"title"];
    self.img = [[UIImageView alloc] initWithImage:
          [UIImage imageNamed:[fillData objectForKey:@"image"]]];
    self.description = [fillData objectForKey:@"description"];
    self.cast = [fillData objectForKey:@"cast"];
}

If you are not getting Image in image view because ur not setting its frame and you are not adding it to view (atleast here)....

Upvotes: 0

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

You are using %d for the object that you get using

[fillData objectForKey:@"year"]

You should use %@ instead as it is most likely an NSNumber object.

Upvotes: 2

Related Questions