ios - 在对象UiTableViewCell上找不到属性

标签 ios objective-c

我试图显示从核心数据中获取数据到我的tableview问题是我明白了。

在UITableView类型的对象上找不到属性yttitle

我已经确保单元格标识符正确,并且yttitle和另一个正确合成。为什么会出现此错误?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];

    // Configure the cell...

    NSManagedObject *device = [devices objectAtIndex:indexPath.row];

    cell.ytTitle.text = [NSString stringWithFormat:@"%@", [device valueForKey: @"songName"]];
    cell.ytAuthor.text = [NSString stringWithFormat:@"%@", [device valueForKey: @"author"]];


    [cell.ytThumbnail.layer setBorderColor: [[UIColor grayColor] CGColor]];
    [cell.ytThumbnail.layer setBorderWidth: 1.0];

    NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@", [device valueForKey: @"link"]]]];
    UIImage* image = [[UIImage alloc] initWithData:imageData];


    cell.ytThumbnail.image = image;




return cell;
}

最佳答案

如果我了解您要执行的操作,则可能不需要创建自定义单元。您可以简单地将UITableViewCell与UITableViewCellStyleSubtitle一起使用,并使用以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];

    // Configure the cell...

    NSManagedObject *device = [devices objectAtIndex:indexPath.row];

    cell.textLabel.text = [NSString stringWithFormat:@"%@", [device valueForKey: @"songName"]];

    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [device valueForKey: @"author"]];

    [cell.imageView.layer setBorderColor: [[UIColor grayColor] CGColor]];
    [cell.imageView.layer setBorderWidth: 1.0];

    NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@", [device valueForKey: @"link"]]]];
    UIImage* image = [[UIImage alloc] initWithData:imageData];


    cell.imageView.image = image;

    return cell;
}

关于ios - 在对象UiTableViewCell上找不到属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21025687/

相关文章:

objective-c - 同时拥有 NSMutableString 和 NSString 的目的是什么?

ios - 为什么这种类型的滚动发生在 PageViewController 中?

objective-c - 链接 libxml 时出错

ios - NSUserDefaults 返回之前的结果

ios - UI 搜索栏。无法更改框架

objective-c - 如何在单击按钮时从文本字段中删除光标?

ios - 为什么我的节点没有出现在 SpriteKit 模板中?

ios - 使用 VoiceOver 在多个 UITableView 之间切换会导致崩溃

ios - SWRevealViewController rightRevealToggle 无法在 Storyboard中使用 UIButton

ios - 在 NavigationBar 上方添加 UIView