这篇文章主要围绕IOSUIAlertViewUIActionSheet展开,旨在为您提供一份详细的参考资料。我们将全面介绍IOSUIAlertViewUIActionSheet,同时也会为您带来'UI
这篇文章主要围绕IOS UIAlertView UIActionSheet展开,旨在为您提供一份详细的参考资料。我们将全面介绍IOS UIAlertView UIActionSheet,同时也会为您带来'UIAlertView' 已弃用:首先在 iOS 9.0 中弃用、DoActionSheet UIActionSheet 替代工具、iOS Swift UIAlertView、ios UIAlertView的实用方法。
本文目录一览:- IOS UIAlertView UIActionSheet
- 'UIAlertView' 已弃用:首先在 iOS 9.0 中弃用
- DoActionSheet UIActionSheet 替代工具
- iOS Swift UIAlertView
- ios UIAlertView
IOS UIAlertView UIActionSheet
那何時才使用 UIAlertView ? 應該是有某些訊息無論如何也要用戶去知道,不是那些無關緊要的事,有可能是你的應用程式發生一些問題,令操作不能繼續的訊息。例如你的應用程式必須依賴網路來拿取資料,但用戶的裝置根本沒有連接網路,這時候你便需要使用 UIAlertView 去提示用戶去連接網路,不然應用程式不能運作。
#import <UIKit/UIKit.h>
@interface ButtonViewController : UIViewController<UIActionSheetDelegate,UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *myButton;
@end
#import "ButtonViewController.h"
#define FIRST_BUTTON 1
#define SECOND_BUTTON 2
#define FIRST_ALERT_VIEW 1
@interface ButtonViewController ()
@end
@implementation ButtonViewController
@synthesize myButton;
- (IBAction)alertOnclick:(id)sender {
CGRect frame = CGRectMake(60, 200, 200, 60);
UIButton *otherBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
otherBtn.backgroundColor = [UIColor clearColor];
[otherBtn setTitle:@"UIAlertView例子" forState:UIControlStateNormal];
otherBtn.frame = frame;
[otherBtn addTarget:self action:@selector(otherBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:otherBtn];
}
- (IBAction)sheetOnclick:(id)sender {
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"您确定?" delegate:self cancelButtonTitle:@"不确定" destructiveButtonTitle:@"非常确定" otherButtonTitles:nil, nil];
[sheet showInView:self.view];
}
- (void) otherBtnClick
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您点击了动态按钮!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"第一项",@"第二项",nil];
//设置标题与信息,通常在使用frame初始化AlertView时使用
alert.title = @"AlertViewTitle";
alert.message = @"AlertViewMessage";
//这个属性继承自UIView,当一个视图中有多个AlertView时,可以用这个属性来区分
alert.tag = FIRST_ALERT_VIEW;
//只读属性,看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);
[alert show];
}
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
//该方法由UIActionSheetDelegate协议定义,在点击ActionSheet的按钮后自动执行
NSString *string=[NSString stringWithFormat:@"你点击了 %@",[actionSheet buttonTitleAtIndex:buttonIndex]];
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:string delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"buttonIndex:%d", buttonIndex);
if (buttonIndex == FIRST_BUTTON && alertView.tag == FIRST_ALERT_VIEW) {
UIAlertView *first = [[UIAlertView alloc] initWithTitle:nil message:@"您点击了第一个按钮" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[first show];
}
if (buttonIndex == SECOND_BUTTON && alertView.tag == FIRST_ALERT_VIEW) {
UIAlertView *second = [[UIAlertView alloc] initWithTitle:nil message:@"您点击了第二个按钮" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[second show];
}
}
//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");
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[self setMyButton:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
'UIAlertView' 已弃用:首先在 iOS 9.0 中弃用
如何解决''UIAlertView'' 已弃用:首先在 iOS 9.0 中弃用?
else {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error",nil)
message:NSLocalizedString(@"Camera not available.",nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK",nil)
otherButtonTitles:nil] show];
self.result(nil);
self.result = nil;
_arguments = nil;
}
}
我收到此错误,我尝试将 ''UIAlertView''
更改为 ''UIAlertController''
仍然收到不同的错误。
解决方法
您可以在 xCode 构建中使用以下 UIAlertController
替换:
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"Error" message:@"Camera not available"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"Ok" style: style:UIAlertActionStyleDefault handler:nil];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
DoActionSheet UIActionSheet 替代工具
DoActionSheet 介绍
DoActionSheet 是一个简单替代 UIActionSheet 的工具,基于块,自定义主题,而且易于结合图片和地图使用。
DoActionSheet 官网
https://github.com/donobono/DoActionSheet
iOS Swift UIAlertView
是否可以在同一个视图控制器中有两个或更多独特的警报?我的目标是iOS 7.1,因此使用以下不推荐使用的UIAlertView方法:
let errorAlert: UIAlertView = UIAlertView() errorAlert.delegate = self errorAlert.message = "Are you sure?" errorAlert.addButtonWithTitle("Yes") errorAlert.addButtonWithTitle("No") errorAlert.show()
此警报转到一个函数,该函数在switch语句中包含一些逻辑.
func alertView(View: UIAlertView!,clickedButtonAtIndex buttonIndex: Int) { ...
到目前为止一切都还可以,但是当我在同一个视图控制器中创建第二个警报时,它也会进入相同的功能.例如,如果我无法与数据库建立连接,我将显示不同的错误消息,但这也会转到上面的alertView函数并运行相同的switch语句.
我正在做一个明显的错误吗?
提前致谢.
解决方法
func alertView(view: UIAlertView!,clickedButtonAtIndex buttonIndex: Int) { if view == errorAlert { // do your stuff.. } else if view == anotherAlertView { // do your stuff for the second AlertView } }
ios UIAlertView
UIAlertView *alert=[[[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil] autorelease];
[alert show];
//alertView 按钮事件 在.h 文件加上UIViewController<UIAlertViewDelegate>
-(void)alertView:(UIAlertView *)theBackAlert clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"%i", buttonIndex);
}
今天关于IOS UIAlertView UIActionSheet的介绍到此结束,谢谢您的阅读,有关'UIAlertView' 已弃用:首先在 iOS 9.0 中弃用、DoActionSheet UIActionSheet 替代工具、iOS Swift UIAlertView、ios UIAlertView等更多相关知识的信息可以在本站进行查询。
本文标签: