I have some extreme difficulties with this use of blocks and inheritance.
I declared a block in the .h file:
void (^block)(BOOL);
initialize it to .m:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
block = ^(BOOL noshow)
{
if(noshow){
AutoTracView.hidden = YES;
MarineTracView.hidden = YES;
}
};
}
return self;
}
Now I pass it, as well as instances of UIVIEw to the UIViewController category:
NSDictionary *const collection = [NSDictionary dictionaryWithObjectsAndKeys:
@"1", AutoTracView,
@"2", MarineTracView,
nil];
[self renderView:[current_unit.unit_type intValue] onCollection:(NSDictionary *)collection withBlock:block];
In UIViewController + extensions.m:
-(void)renderView:(int)value onCollection:(NSDictionary *)collection withBlock:block
{
block(TRUE);
NSString *index = [NSString stringWithFormat:@"%d", value];
UIView *view = [collection objectForKey:index];
view.hidden = NO;
}
Unfortunately, the (TRUE) block throws a compilation error: "The object type identifier is not a function or function pointer"
ok, so I get desparate and just trying to get the block to work, so I delete the block as a parameter call. and just name it in the controller that works. But then another problem arises:
NSDictionary *const collection = [NSDictionary dictionaryWithObjectsAndKeys:
@"1", AutoTracView,
@"2", MarineTracView,
nil];
This does not match the above:
-[UIView copyWithZone:]: unrecognized selector sent to instance 0x6ee2b80
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView copyWithZone:]: unrecognized selector sent to instance 0x6ee2b80'
Am I not allowed to transfer my instances of UIView?
Here is the header file for this:
@property (weak, nonatomic) IBOutlet UIView *AutoTracView;
@property (weak, nonatomic) IBOutlet UIView *MarineTracView;
, -. , "[UIView copyWithZone:]: , "