程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-將電影標題傳遞到視圖中

ios-將電影標題傳遞到視圖中

編輯:編程綜合問答
將電影標題傳遞到視圖中

我能解析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];
}

最佳回答:


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

另外,你不應使用id作為video的類型。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved