- iOS 教程
- iOS - 主页
- iOS - 开始
- iOS - 环境设置
- iOS - Objective-C 基础知识
- iOS - 第一个 iPhone 应用程序
- iOS - 动作和出口
- iOS - 委托
- iOS - UI 元素
- iOS - 加速度计
- iOS - 通用应用程序
- iOS - 相机管理
- iOS - 位置处理
- iOS - SQLite 数据库
- iOS - 发送电子邮件
- iOS - 音频和视频
- iOS - 文件处理
- iOS - 访问地图
- iOS - 应用内购买
- iOS - iAd 集成
- iOS - GameKit
- iOS - 情节提要
- iOS - 自动布局
- iOS - Twitter 和 Facebook
- iOS - 内存管理
- iOS - 应用程序调试
- iOS 有用资源
- iOS - 快速指南
- iOS - 有用资源
- iOS - 讨论
iOS - 提醒
提醒的用法
提醒用于向用户提供重要信息。只有在警报视图中选择选项后,我们才能使用该应用继续进行后续操作。
重要属性
- alertViewStyle
- cancelButtonIndex
- 委托
- 消息
- 按钮数
- 标题
重要方法
- (NSInteger)addButtonWithTitle:(NSString *)title - (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex - (void)dismissWithClickedButtonIndex: (NSInteger)buttonIndex animated:(BOOL)animated - (id)initWithTitle:(NSString *)title message: (NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString*)otherButtonTitles, ... - (void)show
更新 ViewController.h 如下所示 -
使您的类符合警报视图委托协议,方法是将 < UIAlertViewDelegate> 添加到 ViewController.h 中,如下所示。
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIAlertViewDelegate> {
}
@end
添加自定义方法 addAlertView
-(void)addAlertView {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
@"Title" message:@"This is a test alert" delegate:self
cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
[alertView show];
}
实现警报视图委托方法
#pragma mark - Alert view delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
NSLog(@"Cancel button clicked");
break;
case 1:
NSLog(@"OK button clicked");
break;
default:
break;
}
}
}
更新 ViewController.m 中的 viewDidLoad 如下所示 -
(void)viewDidLoad {
[super viewDidLoad];
[self addAlertView];
}
输出
当我们运行应用程序时,我们将得到以下输出 -
ios_ui_elements.htm
广告