@implementation AlertViewTestViewController
/*
Tasks
Creating Alert Views
– initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:
Setting Properties
delegate property
title property
message property
visible property
Configuring Buttons
– addButtonWithTitle:
numberOfButtons property
– buttonTitleAtIndex:
cancelButtonIndex property
firstOtherButtonIndex property
Displaying
– show
Dismissing
– dismissWithClickedButtonIndex:animated: 无例
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
//初始化AlertView
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"AlertViewTest"
message:@"message"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OtherBtn",nil];
//设置标题与信息,通常在使用frame初始化AlertView时使用
alert.title = @"AlertViewTitle";
alert.message = @"AlertViewMessage";
//这个属性继承自UIView,当一个视图中有多个AlertView时,可以用这个属性来区分
alert.tag = 0;
//只读属性,看AlertView是否可见
NSLog(@"%d",alert.visible);
//通过给定标题添加按钮
[alert addButtonWithTitle:@"addButton"];
//按钮总数
NSLog(@"numberOfButtons:%d",alert.numberOfButtons);
//获取指定索引的按钮的标题
NSLog(@"buttonTitleAtIndex:%@",[alert buttonTitleAtIndex:2]);
//获得取消按钮的索引
NSLog(@"cancelButtonIndex:%d",alert.cancelButtonIndex);
//获得第一个其他按钮的索引
NSLog(@"firstOtherButtonIndex:%d",alert.firstOtherButtonIndex);
//显示AlertView
[alert show];
[alert release];
[super viewDidLoad];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#pragma mark -- UIAlertViewDelegate --
//根据被点击按钮的索引处理点击事件
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"clickedButtonAtIndex:%d",buttonIndex);
}
//AlertView已经消失时
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"didDismissWithButtonIndex");
}
//AlertView即将消失时
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"willDismissWithButtonIndex");
}
- (void)alertViewCancel:(UIAlertView *)alertView {
NSLog(@"alertViewCancel");
}
//AlertView已经显示时
- (void)didPresentAlertView:(UIAlertView *)alertView {
NSLog(@"didPresentAlertView");
}
//AlertView即将显示时
- (void)willPresentAlertView:(UIAlertView *)alertView {
NSLog(@"willPresentAlertView");
}
@end
分享到:
相关推荐
对于初学者来说,掌握UIAlertView的使用是至关重要的,因为它涉及到用户体验的关键部分。在本教程中,我们将深入探讨UIAlertView的常用属性设置、点击事件以及如何在其上添加其他视图。 首先,让我们了解...
3. **继承与分类**:如果是在UIAlertView基础上进行扩展,可能会使用Objective-C的分类或Swift的extension来添加方法和属性。 4. **事件处理**:处理alertView的点击事件,比如按钮点击,可能需要实现委托方法或者...
为了在`UIAlertController`中添加`UITextField`,我们使用`addTextField`方法,这会返回一个配置过的文本字段,我们可以进一步定制它的属性,例如键盘类型、占位符等: ```swift let textField = alertController....
这可以通过设置视图的背景图片属性或者使用UIImageView添加背景图片实现。 - 按钮图片:为按钮添加自定义的图片,以提高视觉效果。可以通过UIButton的setImage方法设置按钮的图像。 - 字体描边:通过修改UILabel的...
iPhone 调用相机或者打开相册获取图片 本篇文章主要讲解了在 iPhone 中如何调用相机或者打开相册获取...通过本文,你可以了解到 UIImagePickerController 的使用方法,并在自己的应用程序中实现图片获取和裁剪功能。
例如,使用`pushViewController:animated:`方法,如果你使用的是UINavigationController,或者直接更改视图控制器的`view`属性。 5. **实现视图切换**:在响应工具栏按钮的事件处理方法中,确保正确地显示或隐藏...
此外,还有`init`方法初始化`dialogcanshow`属性,以及`dealloc`方法释放相关资源。 整个`MyHTTPUtil`类的实现利用了`NSURLConnection`或`NSURLSession`(根据iOS版本不同可能使用其中之一)进行网络请求。同步请求...
### 重要知识点解析 #### 一、基础知识 ...以上是《iPhone开发秘籍》第三版中涉及的一些核心知识点和技术细节,覆盖了从基础的Xcode使用到高级的控制器和视图的实现,旨在帮助读者全面掌握iOS开发的关键技术。
然后,使用setView方法加载自定义布局。 3. 定制对话框样式:在项目的res/values目录下创建style.xml文件,定义一个新的主题,该主题继承自AlertDialog主题并覆盖相关属性,如背景、边框、阴影等。 4. 创建...
在iOS应用开发中,"iPhone开发实例 02-Modal Alert"主要涉及到的是苹果设备上显示模态警告视图(Modal Alert)的技术。模态警告视图是一种常见的人机交互方式,它会在用户当前操作的界面之上弹出一个临时窗口,以...
- **UIView 设置成圆角方法**: 使用 `cornerRadius` 属性来设置视图的圆角半径。 - **iPhone 里的 frame 和 bounds**: `frame` 表示视图在父视图坐标系中的位置和大小;`bounds` 表示视图在其自身坐标系中的位置和...
然后,通过`addAction`方法添加按钮,并使用`preferredStyle`属性设置输入框(如果需要)。 - 如果选择自定义UIView,我们需要创建一个新的UIView子类,并在其中布局所有元素,包括背景、图片、按钮和输入框。这...
- **2.1 显示UIAlertView警告**:介绍如何使用UIAlertView显示警告信息。 - **2.2 创建和使用UISwitch开关**:解释如何利用UISwitch控件实现二进制选择功能。 - **2.3 使用UIPickerView选择值**:教授如何创建...
此外,对于iOS 8及以上版本,`UIAlertView`已被弃用,推荐使用`UIAlertController`。因此,在更现代的应用开发中,你需要将上述代码转换为使用`UIAlertController`的方式。尽管方法类似,但`UIAlertController`提供...
6. **兼容性**:由于`UIAlertView`在iOS 8后被弃用,GBAlertView应确保在iOS 8及以上版本的设备上都能正常工作,同时也应考虑iPhone和iPad的屏幕尺寸差异,提供良好的屏幕适配。 7. **代码结构**:GBAlertView的...
但是,UIAlertView在iOS 8之后已经被弃用,因此在新项目中不应再使用。 **UIAlertController** 自iOS 8起,苹果引入了UIAlertController来替代UIAlertView。UIAlertController提供了更大的灵活性,可以创建更复杂的...