开发者

Accessing property inside non-init methods gives bad access

I've begun work on a side project, so the codebase is very small, very little that could go wrong. Something strange is happening. In viewDidLoad I initialise an array set as a property:

@property (nonatomic, retain) NSMutableArray * story_array;

And fill it with data. This printout is fine:

NSLog(@"%@", ((ArticlePreview *)[self.story_array objectAtIndex:0]).article);

I have a gesture recognizer:

UITapGestureRecognizer * openStory = [[UITapGestureRecognizer alloc] initWithTarget:self action:@sel开发者_StackOverflow社区ector(showStory)];

Tapping on it calls a method whose first line is this (i.e. the same NSLog):

NSLog(@"%@", ((ArticlePreview *)[self.story_array objectAtIndex:0]).article);

But this causes a bad access. Accessing story_array itself is fine (it'll say it has however many ArticlePreview objects inside) but accessing their fields is a no-no.

The story_array is init'ed as follows:

self.story_array = [[NSMutableArray alloc] init];


Assignment to the fields of the ARticle Preview object were not done properly. I had:

someField = someValue;

I needed:

self.someField = someValue;

I still find that a bit crazy, but there you go. Solved.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜