2009-11-01 1 views
2

안녕하세요 iPhone 응용 프로그램 개발자,진행률 표시 줄과 취소 단추가있는 사용자 지정 UIAlertview를 구현하는 방법은 무엇입니까?

저는 iPhone 응용 프로그램을 개발 중입니다. 이 응용 프로그램을 사용하면 사용자가 내 서버에 이미지를 업로드 할 수 있습니다. 업로드 진행 상황을 alertView에 표시하려고합니다. 진행률 표시 줄과 함께 사용자 지정 UIAlertView를 구현하는 방법을 설명하기 위해 몇 가지 예제 코드가 필요합니다.

미리 감사드립니다.

답변

13

"빠른"방법은 UIAlertView를 가져 와서 내부 서브 뷰의 위치를 ​​변경하여 진행률 표시 줄을 그 안에 넣는 것입니다. 그것의 단점은 깨지기 쉽고 앞으로 깨질 가능성이 있다는 것입니다.

올바른 방법은 원하는대로 레이아웃 된 UIWindow의 하위 클래스를 구현하고 windowLevel을 UIWindowLevelAlert로 설정하여 현재 창의 앞에 그려야합니다. 뭔가 효과적 일 수는 있지만, 내장 경고 중 하나처럼 보이게하는 것은 많은 노력을 필요로합니다.

그 중 하나를 수행하기 전에 UI를 다시 생각해 보시기 바랍니다. 왜 응용 프로그램을 업로드하는 동안 차단해야합니까? 비동기 적으로 업로드하는 동안 상태 막대를 화면의 어딘가에 배치하고 사용자가 응용 프로그램과 상호 작용할 수있게하는 것이 어떻습니까? 내가 말하는 것에 대해 MMS를 업로드하는 동안 메시지 앱이 어떻게 작동하는지 살펴보십시오.

무언가가 진행되는 동안 응용 프로그램이이를 차단하면 사용자가이를 싫어합니다. 특히 멀티 태스킹이없는 iPhone의 경우에는 더욱 그렇습니다.

+2

+1. 자세한 내용은 휴먼 인터페이스 가이드 라인을 참조하십시오. http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html – Tim

+0

내부에 취소 버튼을 배치하고 싶기 때문에 alertView가 필요합니다. 경고보기. 사용자가 업로드를 취소 할 수있는 방법입니다. – faisal

+0

취소 버튼을 가지고 메인 UI의 다른 곳에 넣을 수 있습니다. 아무 문제가 없습니다. 날 믿어, 너는 경보로 이것을하고 싶지 않아. EDGE 연결을 통해 데이터를 업로드하는 동안 사용자가 경고를 기다리는 것을 실제로 기대합니까? 그렇게하면 사용자가 취소 버튼을 많이 누르게됩니다.하지만 지루하거나 좌절하기 때문에 취소 버튼을 누르기 때문에 좋은 것은 아닙니다. –

0

당신은 UIAlertView를 서브 클래 싱 할 수 체크 아웃 할 수 있습니다. 나는 이같은 일을 당신의 필요에 맞게 바꾼다. 아이폰에 대한 사용자의 기대를 지적

헤더 파일,

#import <Foundation/Foundation.h> 

/* An alert view with a textfield to input text. */ 
@interface AlertPrompt : UIAlertView  
{ 
    UITextField *textField; 
} 

@property (nonatomic, retain) UITextField *textField; 
@property (readonly) NSString *enteredText; 

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okButtonTitle; 

@end 

소스 코드,

#import "AlertPrompt.h" 


@implementation AlertPrompt 

static const float kTextFieldHeight  = 25.0; 
static const float kTextFieldWidth  = 100.0; 

@synthesize textField; 
@synthesize enteredText; 

- (void) drawRect:(CGRect)rect { 
    [super drawRect:rect]; 

    CGRect labelFrame; 
    NSArray *views = [self subviews]; 
    for (UIView *view in views){ 
     if ([view isKindOfClass:[UILabel class]]) { 
      labelFrame = view.frame; 
     } else {  
      view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y + kTextFieldHeight , view.frame.size.width, view.frame.size.height); 
     } 

    } 

    CGRect myFrame = self.frame; 
    self.textField.frame = CGRectMake(95, labelFrame.origin.y+labelFrame.size.height + 5.0, kTextFieldWidth, kTextFieldHeight); 
    self.frame = CGRectMake(myFrame.origin.x, myFrame.origin.y, myFrame.size.width, myFrame.size.height + kTextFieldHeight); 

} 

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle 
{ 

    if (self = [super initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil]) 
    { 
     // add the text field here, so that customizable from outside. But set the frame in drawRect. 
     self.textField = [[UITextField alloc] init]; 
     [self.textField setBackgroundColor:[UIColor whiteColor]]; 
     [self addSubview: self.textField]; 

     // CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 20.0); 
     // [self setTransform:translate]; 
    } 
    return self; 
} 
- (void)show 
{ 
    [textField becomeFirstResponder]; 
    [super show]; 
} 
- (NSString *)enteredText 
{ 
    return textField.text; 
} 
- (void)dealloc 
{ 
    [textField release]; 
    [super dealloc]; 
} 
@end 
관련 문제