2013-05-03 2 views
1

json 파일을 tableview로 구문 분석 할 수는 있지만 영화 제목을 얻고 세부보기를 제목으로 전달하는 방법을 알 수는 없습니다. 다음은, BTW 위 video의 유형으로 id을 사용해서는 안 내 방법ios의 상세보기로 영화 제목 전달하기

- (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]; 

} 

답변

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

입니다.

+0

아무것도 –

+0

죄송합니다, 곧에 말한 일이 없다, 그것은 일을 무엇 id 비디오 대신 사용해야합니까? –

+0

@RodrigoSchreiner 비디오 객체 유형입니다. 예 : 사전이 있다면'NSDictionary * video = ...'를 사용하십시오. – Mar0ux

0

@property (nonatomic, strong) NSString *videoTitle; 

처럼 DetailViewControllervideoTitle라는 속성을 가지고 있다고 가정 그럼 당신은 다만 것 :

- (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]; 
} 
관련 문제