iphone - YouTube ios 提要缩略图

标签 iphone ios objective-c youtube-api

我正在创建一个应用程序来拉入我的 friend 的 YouTube feed。当我运行该应用程序时,我收到错误:

2013-03-30 16:34:04.973 eastcoastdyes[15395:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter'
*** First throw call stack:
(0x1a38012 0x1354e7e 0x1a37deb 0xd4a49d 0xdc11e4 0x3859 0x3538fb 0x3539cf 0x33c1bb 0x34cb4b 0x2e92dd 0x13686b0 0x3014fc0 0x300933c 0x3009150 0x2f870bc 0x2f88227 0x2f888e2 0x1a00afe 0x1a00a3d 0x19de7c2 0x19ddf44 0x19dde1b 0x19927e3 0x1992668 0x298ffc 0x231d 0x2245 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb)

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"Cell Identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
    }

    NSDictionary *video = [self.videos objectAtIndex:indexPath.row];
    cell.textLabel.text = [video objectForKey:@"title"];
    cell.detailTextLabel.text = [video objectForKey:@"uploader"];

    NSURL *url = [[NSURL alloc] initWithString:[video objectForKey:@"data.items.thumbnail.hqdefault"]];
    [cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder"]];

    return cell;

我在 NSURL *url 收到它..请帮忙

最佳答案

您收到错误,因为您的字典为该键返回一个零对象...因此,您应该首先确保您的 video 字典为您的字典返回一个非零对象(字符串) @"data.items.thumbnail.hqdefault" 键,然后才初始化您的 URL...

例如

NSString *imageURLString = [video valueForKeyPath:@"data.items.thumbnail.hqdefault"]; 
if (imageURLString) {
    NSURL *url = [[NSURL alloc] initWithString:imageURLString];
    [cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder"]];
} else {
// set imageView to something else
}

关于iphone - YouTube ios 提要缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15723241/

相关文章:

iphone - 在iphone应用程序开发中如何添加两个uiimageview并将其保存到iphone照片库?

ios - 更改 iPhone 的基本值布局,影响 ipad 布局

ios - 在 Objective C 中 @testable import 的替代方案是什么

ios - 如何在 UIViewController 网格之间进行管理和转换?

iphone - 如何引用 uinavigationcontroller 堆栈中前面的 viewcontroller 属性?

iphone - UITextField - 圆角问题

ios - 防止IOS通知菜单下滑

ios - 当从 xcode 推送通知安装构建时工作但是当安装 ipa 时它不工作

iOS:多语言/多应用,应用商店会被拒绝吗?

ios - 在 iOS 中创建一个可编辑的 TableView ?