2014년 10월 1일 수요일

UIAlertView & Block function

source

//
//  CustomUIAlertView.m
//  patternpie
//
//  Created by MYUNG GU KIM on 10/2/14.
//  Copyright (c) 2014 piestudio. All rights reserved.
//

#import "CustomUIAlertView.h"

@implementation CustomUIAlertView

- (void)showWithBlock:(void (^)(int selectedIndex))complete
{
    self.delegate = self;
    ptrComplete = complete;
    [self show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    ptrComplete((int)buttonIndex);
}


@end




header 

//
//  CustomUIAlertView.h
//  patternpie
//
//  Created by MYUNG GU KIM on 10/2/14.
//  Copyright (c) 2014 piestudio. All rights reserved.
//

#import <UIKit/UIKit.h>

void (^ptrComplete)(int);

@interface CustomUIAlertView : UIAlertView <UIAlertViewDelegate>
{
}
- ( void )showWithBlock: ( void ( ^ )( int selectedIndex) )complete;
@end





using


[[[CustomUIAlertView alloc] initWithTitle:nil message:@"Do you want Challenge?" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil] showWithBlock:^(int selectedIndex) {
            NSLog(@"You selected button %d", selectedIndex);
        }];




댓글 없음:

댓글 쓰기