请教问题,ios7 uialertview输入框 反复调用时崩溃,日志如下

众所周知,当伟大的iOS7系统发布后,表扬的一堆、谩骂的也一片,而对于我们程序员来说最关心的莫过于低版本系统上的程序在搞版本系统上的兼容性问题了。
在iOS6.1几之前,当我们想要做一些提醒用户或临时获取一些数据时,通常会弹出一个模态试图,给予用户提醒,而最常见的做法莫过于直接用UIAlertView添加控件或继承UIAlertView,然后添加自己想要的控件,如:在执行网络连接 &下载等耗时任务时我们会弹出一个view &然后显示一个指示器,具体做法:
- (IBAction)showTraditionAlert:(id)sender {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"正在下载....." message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.delegate =
[alertView show];
#pragma mark -- UIAlertViewDelegate
//实现代理增加网络指示器
- (void)willPresentAlertView:(UIAlertView *)alertV{
indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
indicator.frame = CGRectMake(110, 20, 50, 50);
[alertView addSubview:indicator];
[indicator startAnimating];
[indicator release];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[indicator stopAnimating];
但上面的做法到了iOS7上就没有用了 ,你自己所添加的控件根本显示不出来,也就是说在iOS7上不允许我们更改系统的UIAlertView了(至少目前是这样 beta3版本),我想大家肯定也遇到了这样的问题,那现在改怎么半呢? 可以采用UIWindow的方式实现具体做法网上很多,我比较懒 随便写了点
CustomizedAlertAnimation.h
AlertAnimationDemo
Created by PSH_Chen_Tao on 7/18/13.
Copyright (c) 2013 wolfman. All rights reserved.
//这个类主要时用来对指定的view进行动画,,动画类似UIAlertView的出现和消失
#import &Foundation/Foundation.h&
@protocol CustomizedAlertAnimationD
@interface CustomizedAlertAnimation : NSObject
@property(strong,nonatomic)UIView *
@property(assign,nonatomic)id&CustomizedAlertAnimationDelegate&
-(id)customizedAlertAnimationWithUIview:(UIView *)v;
-(void)showAlertA
-(void)dismissAlertA
@protocol CustomizedAlertAnimationDelegate
-(void)showCustomizedAlertAnimationIsOverWithUIView:(UIView *)v;
-(void)dismissCustomizedAlertAnimationIsOverWithUIView:(UIView *)v;
CustomizedAlertAnimation.m
AlertAnimationDemo
Created by PSH_Chen_Tao on 7/18/13.
Copyright (c) 2013 wolfman. All rights reserved.
#import "CustomizedAlertAnimation.h"
static CGFloat kTransitionDuration = 0.3;
@implementation CustomizedAlertAnimation
-(void)dealloc{
if (delegate) {
delegate =
[view release];
[super dealloc];
-(id)customizedAlertAnimationWithUIview:(UIView *)v{
if (self=[super init]) {
//get the transform of view based on the orientation of device.
-(CGAffineTransform)transformForOrientation{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication ]statusBarOrientation];
switch (orientation) {
case UIInterfaceOrientationLandscapeLeft:
transform =
CGAffineTransformMakeRotation(M_PI*1.5);
case UIInterfaceOrientationLandscapeRight:
transform = CGAffineTransformMakeRotation(M_PI/2);
        //这里写错了,感谢
提出问题,当为倒置方向时才应该旋转
//case UIInterfaceOrientationPortrait:       case UIInterfaceOrientationPortraitUpsideDown:
transform = CGAffineTransformMakeRotation(-M_PI);
transform = CGAffineTransformI
begin the animation
-(void)showAlertAnimation{
view.transform = CGAffineTransformScale([self transformForOrientation], 0.001, 0.001);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kTransitionDuration/1.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(firstBouncesDidStop)];
view.transform = CGAffineTransformScale([self transformForOrientation], 1.1, 1.1);
[UIView commitAnimations];
-(void)dismissAlertAnimation{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kTransitionDuration/2];
[UIView setAnimationDelegate:self];
view.alpha = 0;
[UIView setAnimationDidStopSelector:@selector(dismissAlertAnimationDidStoped)];
[UIView commitAnimations];
mark -- UIViewAnimation delegate
-(void)firstBouncesDidStop{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kTransitionDuration/2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(secondBouncesDidStop)];
view.transform = CGAffineTransformScale([self transformForOrientation], 0.9, 0.9);
[UIView commitAnimations];
-(void)secondBouncesDidStop{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:kTransitionDuration/2];
view.transform = [self transformForOrientation];
[UIView commitAnimations];
//You can do somethings at the end of animation
[self.delegate showCustomizedAlertAnimationIsOverWithUIView:view];
-(void)dismissAlertAnimationDidStoped{
[self.delegate dismissCustomizedAlertAnimationIsOverWithUIView:view];
Created by PSH_Chen_Tao on 7/19/13.
Copyright (c) 2013 wolfman. All rights reserved.
//自定义的
alert view 类
#import &Foundation/Foundation.h&
#import "CustomizedAlertAnimation.h"
@protocol CustomeAlertViewD
@interface CustomeAlertView : UIWindow
&CustomizedAlertAnimationDelegate&
@property(strong,nonatomic)UIView *myV
@property(strong,nonatomic)UIActivityIndicatorView *activityI
@property(strong,nonatomic)CustomizedAlertAnimation *
@property(assign,nonatomic)id&CustomeAlertViewDelegate&
@protocol CustomeAlertViewDelegate
-(void)CustomeAlertViewDismiss:(CustomeAlertView *) alertV
CustomeAlertView.m
Created by PSH_Chen_Tao on 7/19/13.
Copyright (c) 2013 wolfman. All rights reserved.
#import "CustomeAlertView.h"
@implementation CustomeAlertView
@synthesize myV
@synthesize activityI
-(id)init{
if (self=[super init]) {
self.frame = [[UIScreen mainScreen] bounds];
self.backgroundColor = [UIColor clearColor];
//UIWindow的层级 总共有三种
self.windowLevel = UIWindowLevelA
myView = [[UIView alloc]initWithFrame:CGRectMake(30, 140, 260, 200)];
UIButton *okButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[okButton setBackgroundImage:[UIImage imageNamed:@"alert-view-ok-button"] forState:UIControlStateNormal];
[okButton addTarget:self action:@selector(pressoKButton:) forControlEvents:UIControlEventTouchUpInside];
okButton.frame = CGRectMake(90, 130, 80, 40);
[myView addSubview:okButton];
// [okButton release];
activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(105, 75, 50, 50)];
activityIndicator.activityIndicatorViewStyle
= UIActivityIndicatorViewStyleW
[myView addSubview:activityIndicator];
// [activityIndicator release];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:myView.bounds];
[imageView setImage:[[UIImage imageNamed:@"alert-view-bg-portrait"] stretchableImageWithLeftCapWidth:100 topCapHeight:30]];
[myView insertSubview:imageView atIndex:0];
[imageView release];
animation = [[CustomizedAlertAnimation alloc]customizedAlertAnimationWithUIview:myView];
animation.delegate =
[self addSubview:myView];
[myView release];
-(void)show{
[self makeKeyAndVisible];
[animation showAlertAnimation];
-(void)dismiss{
[self resignKeyWindow];
[animation dismissAlertAnimation];
-(void) pressoKButton:(id)sender{
[self dismiss];
#pragma mark -- CustomizedAlertAnimationDelegate
//自定义的alert view出现动画结束后调用
-(void)showCustomizedAlertAnimationIsOverWithUIView:(UIView *)v{
NSLog(@"showCustomizedAlertAnimationIsOverWithUIView");
[activityIndicator startAnimating];
//自定义的alert view消失动画结束后调用
-(void)dismissCustomizedAlertAnimationIsOverWithUIView:(UIView *)v{
NSLog(@"dismissCustomizedAlertAnimationIsOverWithUIView");
[activityIndicator stopAnimating];
[self.delegate CustomeAlertViewDismiss:self];
ViewController.h
Created by PSH_Chen_Tao on 7/19/13.
Copyright (c) 2013 wolfman. All rights reserved.
#import &UIKit/UIKit.h&
#import "CustomeAlertView.h"
@interface ViewController : UIViewController
&UIAlertViewDelegate,CustomeAlertViewDelegate&
- (IBAction)showTraditionAlert:(id)
- (IBAction)showWindowAlert:(id)
@property(strong,nonatomic) UIActivityIndicatorView *
@property(strong,nonatomic)CustomeAlertView *customeAlertV
ViewController.m
Created by PSH_Chen_Tao on 7/19/13.
Copyright (c) 2013 wolfman. All rights reserved.
#import "ViewController.h"
@interface ViewController ()
@implementation ViewController
@synthesize
@synthesize customeAlertV
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (IBAction)showTraditionAlert:(id)sender {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"正在下载....." message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.delegate =
[alertView show];
- (IBAction)showWindowAlert:(id)sender {
customeAlertView = [[CustomeAlertView alloc]init];
customeAlertView.delegate =
[customeAlertView show];
#pragma mark -- UIAlertViewDelegate
//实现代理增加网络指示器
- (void)willPresentAlertView:(UIAlertView *)alertV{
indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
indicator.frame = CGRectMake(110, 20, 50, 50);
[alertView addSubview:indicator];
[indicator startAnimating];
[indicator release];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[indicator stopAnimating];
#pragma mark -- CustomeAlertViewDelegate
-(void)CustomeAlertViewDismiss:(CustomeAlertView *) alertView{
[alertView release];
NSLog(@"CustomeAlertViewDismiss");
对于UIWindow的相关东西可以参考 &/smileEvday/archive//2420362.html#2728097
注意设计到UIWindow显示的工程不能用arc ,具体原因还没找到让我信服的 ,希望知道的大牛可以回复下。。。。。。。
阅读(...) 评论()ios7 在view没有 navigationbar的时候如何适配-中国学网-中国IT综合门户网站
> ios7 在view没有 navigationbar的时候如何适配
ios7 在view没有 navigationbar的时候如何适配
转载 编辑:李强
为了帮助网友解决“ios7 在view没有 navigat”相关的问题,中国学网通过互联网对“ios7 在view没有 navigat”相关的解决方案进行了整理,用户详细问题包括:RT,我想知道:ios7 在view没有 navigationbar的时候如何适配,具体解决方案如下:暂时还未收集到解决方案,如您有解决办法请在下面留言回答通过对数据库的索引,我们还为您准备了:答:你的button是添加在cell上还是cell的子view上 具体说下===========================================答:不知道你说的获取什么意思。 实现下面方法,可以在tableView的cell上滑动时,拉出删除按钮 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewC...===========================================答:请运用如下代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [self.tableView dequeueReusableCellWit...===========================================问:ios开发问题,怎么解决ios7下tableview中的cell只被选中时有一个灰色的...答:没明白你什么意思 是要改变Cell选中的状态么 你所说的透明是什么意思 cell.selectionStyle=UITableViewCellSelectionStyleN 这个就是选中时候无状态 是否是你所说的透明色?===========================================问:ios开发问题,怎么解决ios7下tableview中的cell只被选中时有一个灰色的...答:如果想iOS7中grouped table显示为圆角矩形,解决这个问题的步骤如下 1)创建GroupedTableViewController 从GroupedTableViewController 继承 ,重写 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRo...===========================================问:ios开发问题,怎么解决ios7下tableview中的cell只被选中时有一个灰色的...答:iOS 7手势功能可以更好的帮助我们操作iPhone手机,iOS7手势功能,不仅贯穿了系统设置和原生的一些iOS应用,很多第三方应用也都开始支持手势功能,iOS7手势功能主要有以下几种用法。 1、从左往右手势滑动可返回上一级菜单 在iOS7系统内置内置程序...===========================================问:新手学习,最好说下代码方式怎么调整 如果有代码+XIB两种实现的补分答:cell是不分类型的,只有UITableView会分Plain和Group类型, 还有 UINavigationBar上边一般也不加Cell,所以搞不清楚楼主想要做什么。。===========================================问:以前定制的UIAlertView 安装在 ios7的设备上 已经不能了 各位有没有什么...答:都用这么高的了??===========================================问:系统升级到iOS7,UIScrollView控件滑动指示条消失,projectScrollView.s...答:我在uiscrollview上面add图片,明明是CGRectMake(320*i, 0, 320, 160);但是显示的时候却是往下了几十个像素,不解啊?另吐槽一下,程序一跑,各种控件乱掉。。。 查看原帖&&===========================================
本文欢迎转载,转载请注明:转载自中国学网: []
用户还关注
可能有帮助1335人阅读
UIAlertView及UIActionSheet在ios8中被放弃,其功能将完全由UIAlertController代替:
1.Alert用法
&UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@&This is Title&
&& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &
message:@&This is message&
& & & & & & & & & & & & & & & & & & & & & & & & & & & & & &
preferredStyle:UIAlertControllerStyleAlert];
& & [alert addAction:[UIAlertAction
actionWithTitle:@&Action 1 (Default Style)&
& & & & & & & & & & & & & & & & & & & & & & & style:UIAlertActionStyleDefault
& & & & & & & & & & & & & & & & & & & & & & handler:^(UIAlertAction *action) {
& & & & & & & & & & & & & & & & & & & & & & & & NSLog(@&Action 1 Handler Called&);
& & & & & & & & & & & & & & & & & & & & & & }]];
& & [alert addAction:[UIAlertAction
actionWithTitle:@&Action 2 (Cancel Style)&
& & & & & & & & & & & & & & & & & & & & & & & style:UIAlertActionStyleCancel
& & & & & & & & & & & & & & & & & & & & & & handler:^(UIAlertAction *action) {
& & & & & & & & & & & & & & & & & & & & & & & & NSLog(@&Action 2 Handler Called&);
& & & & & & & & & & & & & & & & & & & & & & }]];
& & [alert addAction:[UIAlertAction
actionWithTitle:@&Action 3 (Destructive Style)&
& & & & & & & & & & & & & & & & & & & & & & & style:UIAlertActionStyleDestructive
& & & & & & & & & & & & & & & & & & & & & & handler:^(UIAlertAction *action) {
& & & & & & & & & & & & & & & & & & & & & & & & NSLog(@&Action 3 Handler Called&);
& & & & & & & & & & & & & & & & & & & & & & }]];
& & [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
& & & & UITextField * tf = [[UITextField
alloc]initWithFrame:CGRectMake(0,
presentViewController:alert animated:YES
completion:nil];
2,actionsheet用法
&UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
& & [alertController addAction:[UIAlertAction
actionWithTitle:@&111&
& & & & & & & & & & & & & & & & & & & & & & & & & & & &
style:UIAlertActionStyleDefault
& & & & & & & & & & & & & & & & & & & & & & & & & & &
handler:^(UIAlertAction *action) {
& & & & & & & & & & & & & & & & & & & & & & & & & & & & &
NSLog(@&111&);
& & & & & & & & & & & & & & & & & & & & & & & & & & & }]];
& & [alertController addAction:[UIAlertAction
actionWithTitle:@&222&
& & & & & & & & & & & & & & & & & & & & & & & & & & & &
style:UIAlertActionStyleCancel
& & & & & & & & & & & & & & & & & & & & & & & & & & &
handler:^(UIAlertAction *action) {
& & & & & & & & & & & & & & & & & & & & & & & & & & & & &
NSLog(@&222&);
& & & & & & & & & & & & & & & & & & & & & & & & & & & }]];
presentViewController:alertController animated:YES
completion:nil];
版本判断语句
#define iOS(version) (([[[UIDevice currentDevice] systemVersion] intValue] &= version)?1:0)
可进行判断添加alertController或是aletView和actionsheet
3.新的问题,当在ios8下做好判断之后,返回ios7或ios6运行xcode,报错-------
原因:UIAlertController只在ios8下的框架里由此文件,ios7及以下版本没有,但编译的时候还是会进行编译(虽然运行时不走这部分代码)
解决方法:编译时进行判断,只有在ios8SDK下编译此部分
#if __IPHONE_OS_VERSION_MAX_ALLOWED &= 80000
& & & & & & &&alertcontroller相关代码&
重新运行xcode,ok,可以正常运行了.
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:15134次
排名:千里之外
原创:16篇
转载:29篇
(2)(2)(2)(6)(6)(3)(2)(5)(1)(4)(4)(7)(1)请教问题,ios7 UIAlertView 反复调用时崩溃,日志如下_百度知道
请教问题,ios7 UIAlertView 反复调用时崩溃,日志如下
我有更好的答案
看有没有实现代理方法,而且你用的是delegate:self 你的程序应该在这部分有警告吧
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁请教问题,ios7 UIAlertView 反复调用时崩溃,日志如下_百度知道
请教问题,ios7 UIAlertView 反复调用时崩溃,日志如下
提问者采纳
self 你的程序应该在这部分有警告吧,而且你用的是delegate, 看有没有实现代理方法
电脑网络爱好者
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}

我要回帖

更多关于 ios自定义uialertview 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信