+(DisplayErrorMsg *)sharedDisplayErrorMsg
{
static DisplayErrorMsg *instance = nil;
@synchronized(instance)
{
if (instance == nil) {
instance = [[DisplayErrorMsg alloc] init];
}
}
return instance;
}
-(void)showAlertView:(NSString *)title Message:(NSString *)msg
{
NSArray *array = [NSArray arrayWithObjects:title,msg, nil];
[self performSelectorOnMainThread:@selector(doAlert:) withObject:array waitUntilDone:NO];
}
-(void)doAlert:(NSArray *)array
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[array objectAtIndex:0] message:[array objectAtIndex:1] delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.window addSubview:alert];
[alert show];
[alert release];
}
{
static DisplayErrorMsg *instance = nil;
@synchronized(instance)
{
if (instance == nil) {
instance = [[DisplayErrorMsg alloc] init];
}
}
return instance;
}
-(void)showAlertView:(NSString *)title Message:(NSString *)msg
{
NSArray *array = [NSArray arrayWithObjects:title,msg, nil];
[self performSelectorOnMainThread:@selector(doAlert:) withObject:array waitUntilDone:NO];
}
-(void)doAlert:(NSArray *)array
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[array objectAtIndex:0] message:[array objectAtIndex:1] delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.window addSubview:alert];
[alert show];
[alert release];
}
单例模式与UIAlertView示例
本文介绍了一个使用单例模式实现的错误显示类,并展示了如何利用UIAlertView来展示错误消息。通过实例化单例对象并调用其方法,可以在iOS应用中弹出带有指定标题和消息的警告视图。

被折叠的 条评论
为什么被折叠?



