eXit_door 2013-05-03 03:23 采纳率: 0%
浏览 2184
已采纳

将电影标题传递到视图中

我能解析Json文件到表视图中,但是不知道怎么获取电影标题,作为标题传递到详细视图中。

我用这样的方法:

- (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];
}
  • 写回答

2条回答

  • xinyoulingxi1_tong 2013-05-03 07:00
    关注
    id video = [self.model.videos objectAtIndex:indexPath.row];
    vc.title = [video objectForKey:@"title"];
    

    另外,你不应使用id作为video的类型。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog