0

I'm using a block for completion handler. How to access a imageView/UIElements inside a block,

     [storyImageView setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:Nil completed:^(UIImage *storyImage,NSError *error,SDImageCacheType cacheType)
   {
       //need to access storyImageView inside a block
   }];
Muddu Patil
  • 713
  • 1
  • 11
  • 24
user2823044
  • 315
  • 2
  • 5
  • 14
  • This question doesn't make sense. The imageView and "UIElements" you mention, are they properties of the class calling the block? – Woodstock Mar 28 '14 at 07:28
  • imageView is an instance of UIImageView...inside the block if we try to access imageView object it is warning that capturing imageView inside a block leads to retain cycle – user2823044 Mar 28 '14 at 07:32
  • You need to create a weak local reference to the imageView – Woodstock Mar 28 '14 at 07:36

1 Answers1

0

look at this question Get UIImageView using Afnetworking and put it in an array

as i understand you are using Afnetworking category for setting uiimages.

Your image will be automaticaly set. look at the method "setImage..."

Blocks here for example to reload table data.

If you need to update ui/ access ui elements you need to do it in main thread

dispatch_async(dispatch_get_main_queue(), ^{
    //updates
});

if you have some instances (no matter UI or not) and you want access them in block you should add "__block" before it.

e.g.

__block NSString *myString = @"test";
Community
  • 1
  • 1
Roma
  • 1,107
  • 9
  • 19