Passing movie title to a detail view in ios

I am able to parse a json file to a tableview but I can't figure out how to get the movie title and pass to my detail view as the title. Below is my methods

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"movieCell";

    movieCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    id video = [self.model.videos objectAtIndex:indexPath.row];
    NSString *rl = [video objectForKey:@"release_date"];
    NSString *imageURL;
    if ([[video objectForKey:@"poster_path"] class] != [NSNull class])
        imageURL = [video objectForKey:@"poster_path"];
    else
        imageURL = @"icon.jpg";

    if (rl != (NSString *)[NSNull null]){
            NSString *dateStr = rl;
            // Convert string to date object
            NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
            [dateFormat setDateFormat:@"yyyy-MM-dd"];
            NSDate *date = [dateFormat dateFromString:dateStr];

            // Convert date object to desired output format
            [dateFormat setDateFormat:@"MM/YYYY"];
            NSString *released = @"Released: ";
            NSString *fullDate;
            dateStr = [dateFormat stringFromDate:date];
            fullDate = [NSString stringWithFormat:@"%@ %@", released, dateStr];
            cell.videoDescriptionLabel.text = fullDate;
    }
    else{
        cell.videoDescriptionLabel.text = @"N/A";
    }
    cell.videoTitleLabel.text = [video objectForKey:@"title"];      
    NSString* thumbnailURL = [NSString stringWithFormat:@"http://cf2.imgobject.com/t/p/w154%@",imageURL];
    [cell.videoThumbnail setImageWithURL:[NSURL URLWithString:thumbnailURL] placeholderImage:[UIImage imageNamed:@"icon"]];
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    DetailViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"boot"];
    [self.navigationController pushViewController:vc animated:YES];

}

Answers


id video = [self.model.videos objectAtIndex:indexPath.row];
vc.title = [video objectForKey:@"title"];

Btw, you shouldn't use id as the type of video above.


Assuming that you have a property called videoTitle within your DetailViewController like this

@property (nonatomic, strong) NSString *videoTitle;

Then you'd just do:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    DetailViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"boot"];
    vc.videoTitle = [[self.model.videos objectAtIndex:indexPath.row] objectForKey:@"title"];
    [self.navigationController pushViewController:vc animated:YES];
}

Need Your Help

CFForm validation and onclick before submit

javascript forms validation coldfusion onclick

I have been trying to validate a few fields before submitting a form. Once the fields are validated by CF I want to pop up a sign in form if the user is not signed in. However, the problem is tha...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.