//
// PromptView.h
// TabBarTest
//
// Created by kimziv on 7/29/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol PromptViewDelegate;
@interface PromptView : NSObject<UIActionSheetDelegate> {
UIActionSheet *_promptView;
id<PromptViewDelegate> _delegate;
}
@property(nonatomic,assign)id<PromptViewDelegate> delegate;
+ (PromptView *)sharedPromptView;
+ (void)setSharedDelegate:(id<PromptViewDelegate>)delegate;
- (void)showPromptView:(NSString *)promptText;
- (void)dismissPromptView;
@end
@protocol PromptViewDelegate <NSObject>
@optional
-(void)cancelButtonDidClicked:(id)sender;
@end
//
// PromptView.m
// TabBarTest
//
// Created by kimziv on 7/29/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import “PromptView.h”
#import “SynthesizeSingleton.h”
@implementation PromptView
@synthesize delegate=_delegate;
SYNTHESIZE_SINGLETON_FOR_CLASS(PromptView);
- (void)dealloc {
[_promptView release];
[super dealloc];
}
#pragma mark PromptView
- (void)createStatusView{
CGRect frame = CGRectMake(280, 10, 16, 16);
UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
_promptView = [[UIActionSheet alloc] initWithTitle:@”Connecting…” delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
_promptView.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[_promptView addSubview:progressInd];
[progressInd release];
UIButton *cancelBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
cancelBtn.frame=CGRectMake(30, 10, 40, 20);
//UIButton *cancelBtn=[[UIButton alloc] initWithFrame:CGRectMake(20, 10, 50, 30)];
cancelBtn.titleLabel.font=[UIFont systemFontOfSize:12];
[cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
//[cancelBtn setBackgroundImage:[UIImage imageNamed:<#(NSString *)#>] forState:UIControlStateNormal];
cancelBtn.backgroundColor=[UIColor clearColor];
cancelBtn.alpha=0.5;
[cancelBtn addTarget:self action:@selector(cancelSend:) forControlEvents:UIControlEventTouchUpInside];
[_promptView addSubview:cancelBtn];
//[cancelBtn release];
}
-(IBAction)cancelSend:(id)sender{
[self dismissPromptView];
if ([_delegate respondsToSelector:@selector(cancelButtonDidClicked:)]) {
[_delegate cancelButtonDidClicked:sender];
}
}
- (void)showPromptView:(NSString *)statusText{
if(!_promptView)
{
[self createStatusView];
}
if(![_promptView superview])
[_promptView showInView:[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0]];
[_promptView setTitle:statusText];
}
- (void)dismissPromptView{
if([_promptView superview])
[_promptView dismissWithClickedButtonIndex:0 animated:YES];
if(_promptView)
{
[_promptView release];
_promptView = nil;
}
}
#pragma mark – UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
}
+(void)setSharedDelegate:(id<PromptViewDelegate>)delegate{
[self sharedPromptView].delegate=delegate;
}
@end
//
// SynthesizeSingleton.h
// TabBarTest
//
// Created by kimziv on 7/29/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname)
static classname *shared##classname = nil;
+ (classname *)shared##classname
{
@synchronized(self)
{
if (shared##classname == nil)
{
shared##classname = [[self alloc] init];
}
}
return shared##classname;
}
+ (id)allocWithZone:(NSZone *)zone
{
@synchronized(self)
{
if (shared##classname == nil)
{
shared##classname = [super allocWithZone:zone];
return shared##classname;
}
}
return nil;
}
- (id)copyWithZone:(NSZone *)zone
{
return self;
}
- (id)retain
{
return self;
}
- (NSUInteger)retainCount
{
return NSUIntegerMax;
}
- (void)release
{
}
- (id)autorelease
{
return self;
}