0

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.

4

1 回答 1

3

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;
}
于 2013-06-22T08:39:09.417 回答