您的位置:首页 > 产品设计 > UI/UE

IOS 7 自定义的UIAlertView不能在iOS7上正常显示

2013-11-29 09:37 423 查看
本文转载至 http://blog.csdn.net/hanbing861210/article/details/13614405
众所周知,当伟大的iOS7系统发布后,表扬的一堆、谩骂的也一片,而对于我们程序员来说最关心的莫过于低版本系统上的程序在搞版本系统上的兼容性问题了。

在iOS6.1几之前,当我们想要做一些提醒用户或临时获取一些数据时,通常会弹出一个模态试图,给予用户提醒,而最常见的做法莫过于直接用UIAlertView添加控件或继承UIAlertView,然后添加自己想要的控件,如:在执行网络连接 下载等耗时任务时我们会弹出一个view 然后显示一个指示器,具体做法:

但上面的做法到了iOS7上就没有用了 ,你自己所添加的控件根本显示不出来,也就是说在iOS7上不允许我们更改系统的UIAlertView了(至少目前是这样2013/07/18 beta3版本),我想大家肯定也遇到了这样的问题,那现在改怎么半呢? 可以采用UIWindow的方式实现具体做法网上很多,我比较懒 随便写了点

//
//  ViewController.m
//  AlertDemo
//
//  Created by PSH_Chen_Tao on 7/19/13.
//  Copyright (c) 2013 wolfman. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize indicator;

@synthesize customeAlertView;

- (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 = self;
[alertView show];
}

- (IBAction)showWindowAlert:(id)sender {

customeAlertView = [[CustomeAlertView alloc]init];
customeAlertView.delegate = self;

[customeAlertView show];
}

#pragma mark -- UIAlertViewDelegate

//实现代理增加网络指示器
- (void)willPresentAlertView:(UIAlertView *)alertView;{
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");
}
@end


对于UIWindow的相关东西可以参考 http://www.cnblogs.com/smileEvday/archive/2012/03/27/2420362.html#2728097
注意设计到UIWindow显示的工程不能用arc ,具体原因还没找到让我信服的 ,希望知道的大牛可以回复下。。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐