UIAlertView

API:

#import <Foundation/Foundation.h>

#import <UIKit/UIKitDefines.h>

#import <UIKit/UITextField.h>

#import <UIKit/UIView.h>


typedef NS_ENUM(NSInteger, UIAlertViewStyle) {

    UIAlertViewStyleDefault = 0,

    UIAlertViewStyleSecureTextInput,

    UIAlertViewStylePlainTextInput,

    UIAlertViewStyleLoginAndPasswordInput

};


@protocol UIAlertViewDelegate;        遵守的协议

@class UILabelUIToolbarUITabBarUIWindowUIBarButtonItemUIPopoverController;


NS_CLASS_AVAILABLE_IOS(2_0) @interface UIAlertView : UIView


- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id/*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATIONNS_EXTENSION_UNAVAILABLE_IOS("Use UIAlertController instead.");


@property(nonatomic,assignid /*<UIAlertViewDelegate>*/ delegate;    // weak reference
一般用于初始化的时候直接赋值 

@property(nonatomic,copyNSString *title;

@property(nonatomic,copyNSString *message;  

当一个view中有多个alertView时,用tag值区分
alert.tag=0

添加按钮并直接给标题 

- (NSInteger)addButtonWithTitle:(NSString *)title;
指定索引的按钮标题 

- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
 按钮总数

@property(nonatomic,readonlyNSInteger numberOfButtons;
取消按钮的索引值 

@property(nonatomicNSInteger cancelButtonIndex;


获取其他按钮的索引值

@property(nonatomic,readonlyNSInteger firstOtherButtonIndex;
 

@property(nonatomic,readonly,getter=isVisible) BOOL visible;


显示弹出的方法,不掉用,则不显示整个alertview控件

- (void)show;


- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;


alert显示的样式,默认的样式为UIAlertViewStyleDefault(一共有4个样式,在上面typedef NS_ENUM)

@property(nonatomic,assignUIAlertViewStyle alertViewStyle NS_AVAILABLE_IOS(5_0);


/* Retrieve a text field at an index - raises NSRangeException when textFieldIndex is out-of-bounds. 

   The field at index 0 will be the first text field (the single field or the login field), the field at index 1 will be the password field.  
/ *检索文本字段索引,提高NSRangeException textFieldIndex时是禁止入内的。

  在索引0将成为第一个文本字段(单一字段或登录字段),在指数1将密码字段。* / */

- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);


@end


@protocol UIAlertViewDelegate <NSObject>

@optional

选中的那个button处理点击事件,传递的参数是button的索引值

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;


- (void)alertViewCancel:(UIAlertView *)alertView;    取消按钮的事件


- (void)willPresentAlertView:(UIAlertView *)alertView;    即将显示时的事件

- (void)didPresentAlertView:(UIAlertView *)alertView;        已经显示时的事件


- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;    即将消失时执行的事件

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:

(NSInteger)buttonIndex;    已经消失时执行的事件


- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;


@end



基于UITableView

//当选中某行,所触发的方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{

//    屏幕上弹出的提示框(可以不遵守UIAlertViewDelegate协议也能使用)

    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"这是个UIAlertView"message:@"啦啦" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];

    alert.tag=100;

    [alert show];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex==0) {

        NSLog(@"点击的是第一个按钮");//可以任意写想要的事件

    }

    else if (buttonIndex==1){

        NSLog(@"点击的是第二个按钮");

   }

    else if (buttonIndex==2){

        NSLog(@"点击的是第三个按钮");

    }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值