I have a UIImageView,while loading it for the first time i should not have any image so i will make the image nil.
self.myImageView.image = nil;
on pressing a button i need the image to be loaded using the imageWithD开发者_StackOverflow中文版ata method as i have a image in NSData.While i am trying to do this the application crashes.I even tried allocating and using with initWithData that is of no help.
self.myImageView.image = [UIImage imageWithData:myImageData];
But, wheni use this method while loading for the first time using my data and then try to put it into Image view with the button press it works fine.
Please help me regarding this, Thanks.
Try
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:myImageData]];
Update:
If the imageView is created without using initWithImage:
imageView.image becomes nil by default.
The problem was the scope of Variables. in view did load data was correct but in other method i was not getting the image so i used self.myImageData in view did load as well as in IB action method, now it works fine.
Note: It would be diffcult to find the answer for this question in the comment so i have made it as answer and accepted it as correct
精彩评论