我试图显示从核心数据中获取数据到我的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/