Actually ,I’ve been looking around at how to call a method from a block.
I am trying to fetch all images from iphone photo app .Here is the code….
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
if(group != nil) {
[self.groups addObject:group];
[group enumerateAssetsUsingBlock:selectionBlock];
}
};
[library enumerateGroupsWithTypes:groupTypes
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(@"A problem occurred");}];
In selectionBlock … I just want to add an action when user click on any image.
so I tried this code ..
[imgView addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
buttonPressed is also defined in the same .m file.
- (void) buttonPressed: (id) sender {
UIAlertView* av = [[UIAlertView alloc] initWithTitle:@"Howdy!"
message:@"You tapped me."
delegate:nil
cancelButtonTitle:@"Cool"
otherButtonTitles:nil];
[av show];
}
But in selectionBlock I am getting “No visible @interface for ‘UIImageView’ declares the selector ‘addTarget:action:forControlEvents’ “
I am new to iOS programming. so any help would be very, very appreciated!
-addTarget:action:forControlEvents:is a method onUIControl.UIButton,UISwitch, and so on are all subclasses ofUIControl.UIImageView, however, is not, so it does not respond to that selector. Since yourimgViewvariable is aUIImageView, the compiler won’t let you call this method on it. This has nothing to do with calling it in from a block, btw – but only with what methods objects declare they respond to.Hope this helps!