Error: property 'data' not found on object of type 'id'

☆樱花仙子☆ 提交于 2019-12-11 19:42:03

问题


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.

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.


回答1:


The bracket notation would look something like:

[[[self detailItem] data] setTitle:[[self titleField] text]];

The actual error sounds more like a type error though. Either the detailItem's type doesn't actually have a data property, or it's not obvious what type of class detailItem is.




回答2:


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;

Your "object" that you are passing to the detail view controller is a NSDate object.

You cannot set a title to a NSDate object.

You also have a problem when you do

[[self detailItem] setFullImage:fullImage];
[[self detailItem] setThumbImage:thumbImage];

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.

iOS Tutorial: How To Create A Simple iPhone App



来源:https://stackoverflow.com/questions/19060609/error-property-data-not-found-on-object-of-type-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!