IOS开发5----自定义CustomAlertView的回调。

1.在.h中:写入

#import <UIKit/UIKit.h>

@interface CustomAlertViewController : UIViewController

{

    id delegateID;

    NSString *cancelFun;

    NSString *certainFun;

}

@property (assign, nonatomic) id delegateID;

@property (retain, nonatomic) NSString *cancelFun;

@property (retain, nonatomic) NSString *certainFun;

@property (retain, nonatomic) IBOutlet UIView *innerView;

- (id)initAlert:(id)delegate cancelFun:(NSString*)cancel certainFun:(NSString *)certain;

-(IBAction)CancelClicked:(id)sender;

-(IBAction)OkClicked:(id)sender;

@end

2.在.m中(别忘了@synthesize及nil,release)

加入方法:

- (id)initAlert:(id)delegate cancelFun:(NSString*)cancel certainFun:(NSString *)certain

{

    self = [super initWithNibName:@"CustomAlertViewController" bundle:nil];

    if (self) {

        // Custom initialization

        delegateID = delegate;

        cancelFun = cancel;

        certainFun = certain;

    }

    return self;

}

- (IBAction)CancelClicked:(id)sender

{

    [delegateID performSelector:NSSelectorFromString(cancelFun)];

}

- (IBAction)OkClicked:(id)sender

{

    [delegateID performSelector:NSSelectorFromString(certainFun)];

}

3.调用的时候

-(void)showCustomAlertView

{

    if (customAlertViewController ==nil) {

        customAlertViewController = [[CustomAlertViewController alloc]initAlert:self cancelFun:@"cancelFun" certainFun:@"CertainFun"];

    }

    [self.view addSubview:customAlertViewController.view];

}

-(void)cancelFun

{

   // [self hiddenCustomAlertView];

}

-(void)CertainFun

{

    //[self hiddenCustomAlertView];

    //for (UIView *view in self.view.subviews) {

    //    [view removeFromSuperview];

  //  }

  //    [[AppDelegate app].rootViewController hiddenFirstHomeView];

   // [[AppDelegate app].rootViewController showLoginView];

}


这样customviewController出现后,点击取消会 调用-(void)cancelFun方法,确定会调用-(void)CertainFun方法;

你可能感兴趣的:(IOS开发5----自定义CustomAlertView的回调。)