弹出对话框的实现

    技术2022-05-19  18

    实现方法和actionSheet十分类似,先在类定义的时候加上UIAlertViewDelegate, 用于以后处理按钮事件

    @interface XXXController : UIViewController <UIAlertViewDelegate> {

     

    调用方法为

    UIAlertView *alert = [[UIAlertView alloc]

      initWithTitle:@"titile"

      message:@“Message displayed"

      delegate: self

      cancelButtonTitle:@"Cancel"

      otherButtonTitles:@"OK",nil];

    [alert show];                //显示

    [alert release];

     

    delegate指定处理事件的类,记住最后一定要release,一定要release!

     

     

    处理事件的方法为实现UIAlertViewDelegate的方法

    - (void)alertView:(UIAlertView *)alertView 

    clickedButtonAtIndex:(NSInteger)buttonIndex

    {

    NSString *newText = [[NSString alloc] initWithFormat:@"%d",buttonIndex];

    leftLabel.text = newText;

    [newText release];

    }

     

    心得:这种方法是比较麻烦的,但习惯可能会感觉工整,设计思路的一贯性很好


    最新回复(0)