The block is a property defined in GridScrollView:
typedef BoxView* (^RenderBlock)(NSDictionary* json, CGRect);
@interface GridScrollView : PagingScrollView
@property (nonatomic, copy) RenderBlock renderBlock;
I want to use it like this:
switch(current.tag)
{
case 1:
scrollView.renderBlock = ^(NSDictionary* json, CGRect frame)
{
//returns a boxview
}
break;
case 2:
scrollView.renderBlock = ^(NSDictionary* json, CGRect frame)
{
//returns a different boxview
}
break;
}
While this code works fine the first time around, when it gets reassigned I get an EXC_BAD_ACCESS (code=2, address=0x0) error. What's happening here?
Since the call to the block is itself performing the declaration of an object, try adding an extra pair of braces around it:
case 1: {
scrollView.renderBlock = ^(NSDictionary* json, CGRect frame) {
//returns a boxview
}
}
break;
Although I don't know why it would run as is the first time and then crash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With