错误:在“id"类型的对象上找不到属性“data" [英] Error: property 'data' not found on object of type 'id'
问题描述
我在 titleFieldValueChanged 方法中收到此错误,当用户更改文本字段的值以更新数据模型时会调用该方法.
I get this error in the method titleFieldValueChanged which is called when the user changes the value of the text field to update the data model.
在DetailViewController.m中:
In DetailViewController.m:
- (IBAction)titleFieldTextChanged:(id)sender
{
self.detailItem.data.title = self.titleField.text;
}
我知道我必须用括号表示法来写这个,对吗?但我不知道该怎么做.
I know I have to write this in bracket notation, correct? But I can't figure out how to do that.
推荐答案
在继续之前查看您的代码(我稍微更改了它 - 做同样的事情).您发送的代码在尝试从 master 转至 detail 时崩溃.这些是我发现的更大的问题.
Looking at your code, before you segue (i changed it slightly - does same thing) . The code you sent crashes, when trying to segue from master to detail. These are the bigger issues I found.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
DetailViewController *dvc = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _exercises[indexPath.row];
dvc.detailItem = object;
}
}
// in detail view
@property (strong, nonatomic) NSDate *detailItem;
你传递给细节视图控制器的对象"是一个 NSDate 对象.
Your "object" that you are passing to the detail view controller is a NSDate object.
不能为 NSDate 对象设置标题.
You cannot set a title to a NSDate object.
你做的时候也有问题
[[self detailItem] setFullImage:fullImage];
[[self detailItem] setThumbImage:thumbImage];
再次尝试将图像设置为 NSDate 对象.
Again your trying to set an image to your NSDate object.
我建议您按照本教程进行操作,它将展示您正在尝试制作的内容的一个很好的示例,正如您提到的,您是初学者.
I suggest you follow along with this tutorial, it will show a good example of what you are trying to make, as you mentioned you are a beginner.
这篇关于错误:在“id"类型的对象上找不到属性“data"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!