Reputation: 733
I'm creating an iphone app that at one page before you can move on to the next you have to select a button or an alert will pop up.
.h
<UIAlertViewDelegate>
@property (nonatomic, retain) IBOutletCollection(UIButton) NSArray *buttons;
.m
-(BOOL)validateTag:(NSArray *)buttons {
[self.buttons enumerateObjectsUsingBlock:^(id obj) {
UIButton *button = (UIButton *)obj;
if (button != button.enabled){
return NO;
}
return YES;
} ];
}
-(IBAction)save:(id)sender{
if (![self validateTag:_buttons]) {
[self alertMessage:@"Invalid ":@"Please choose a Tag"];
return;
}
else {
....display other viewcontroller
}
The error I'm getting is
`Incompatible pointer types sending bool to parameter of type void`
on line
[self.buttons enumerateObjectsUsingBlock:^(id obj)
Anyways of getting around this?
Thanks.
Upvotes: 0
Views: 82
Reputation: 119031
The block you're using doesn't have a return type, so you can't return the BOOL value from there. You should use a __block
variable instead:
-(BOOL)validateTag:(NSArray *)buttons
{
__block BOOL result = NO;
[self.buttons enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIButton *button = (UIButton *)obj;
if (button.enabled) {
result = YES;
*stop = YES;
}
}];
return result;
}
Upvotes: 3