2011-02-23 8 views
2

UIActionsheet에서 textField를 만들지 만 텍스트를 입력 할 수 없으며 그 중 하나에 대해 생각할 수 있습니까?UITextField에있는 UITextField에서 텍스트 입력을 활성화하는 방법은 무엇입니까?

-(void)commentsMethod: (id) sender { 

    //setup UITextField for the UIActionSheet 
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 28, 320, 150)]; 
    //textField.delegate=self; 
    textField.autocorrectionType = UITextAutocorrectionTypeNo; 
    [textField setBackgroundColor:[UIColor clearColor]]; 
    [textField setBorderStyle:UITextBorderStyleRoundedRect]; 
    [textField becomeFirstResponder]; 

    //CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>) 

    UIButton *btn = [[UIButton alloc] init]; 
    [btn setFrame:CGRectMake(0, 0, 100, 100)]; 
    [btn setTitle:@"dismiss" forState:UIControlStateNormal]; 
    [btn setBackgroundColor:[UIColor clearColor]]; 
    [btn addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; 



    UIActionSheet *myActionSheet; 
    myActionSheet = [[UIActionSheet alloc] initWithTitle:@"Comments" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil]; 
    myActionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
    [myActionSheet showInView:self.view]; 
    myActionSheet.userInteractionEnabled=YES; 

    [myActionSheet setFrame:CGRectMake(0, 20, 320,600)]; 
    [myActionSheet insertSubview:textField atIndex:0]; 
    [myActionSheet insertSubview:btn atIndex:1]; 
    //[self.myActionSheet dismissWithClickedButtonIndex:0 animated:NO]; 

    //memory management 
    [textField release];  
    [myActionSheet release];   
} 
+0

정확히 텍스트를 입력 할 수없는 이유는 무엇입니까? – Vladimir

+0

키보드를 클릭하는 것과 같은 것 (예 : A B C D ,,,,) 아무것도 textField에 표시되지 않습니다. –

답변

2

헤이 비어를 따를 때

내 코딩, 당신은 여기에 복용해야 약간 다른 접근 방법이있다. 여기 제가 제안하는 것이 있습니다.

.H 파일 코드

#import <UIKit/UIKit.h> 

    @interface trialViewController : UIViewController <UIActionSheetDelegate, UITextFieldDelegate> { 

     UITextField *TextField; 

    } 

    -(void) CreateSlideOut; 
    -(void) removePopUp; 
    -(void) slidePopup; 
    @end 

하는 .m 코드

#import "trialViewController.h" 

@implementation trialViewController 


CGRect backToOriginal; 
UIView *popup; 

- (void)viewDidLoad { 

    [self CreateSlideOut]; 
    [self slidePopup]; 
    [super viewDidLoad]; 
} 


-(void) CreateSlideOut 
{ 

    CGRect frame=CGRectMake(0, CGRectGetMaxY(self.view.bounds), 320, 480); 

    backToOriginal=frame; 

    popup=[[UIView alloc]initWithFrame:frame]; 

    popup.backgroundColor = [UIColor orangeColor]; 

    [self.view addSubview:popup]; 

} 


-(void) slidePopup 
{ 

    UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    button.frame=CGRectMake(60, 190, 200,40); 
    button.backgroundColor=[UIColor clearColor]; 

    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 

    [button setTitle:@"Dismiss" forState:UIControlStateNormal]; 
    [button addTarget:self action:@selector(DismissClicked:) forControlEvents:UIControlEventTouchUpInside]; 

    TextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 28, 280, 150)]; 
    TextField.delegate=self; 
    TextField.autocorrectionType = UITextAutocorrectionTypeNo; 
    [TextField setBackgroundColor:[UIColor clearColor]]; 
    [TextField setBorderStyle:UITextBorderStyleRoundedRect]; 

    [popup addSubview:TextField]; 
    [popup addSubview:button]; 

    CGRect frame=CGRectMake(0, 0, 320, 480); 

    [UIView beginAnimations:nil context:nil]; 

    [popup setFrame:frame]; 

    [UIView commitAnimations]; 


} 

-(void) removePopUp 

{ 
    [UIView beginAnimations:nil context:nil]; 

    [popup setFrame:backToOriginal]; 

    [UIView commitAnimations]; 

    [TextField resignFirstResponder]; 
} 

-(IBAction) DismissClicked : (id) sender 
{ 

    [self removePopUp]; 
} 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    NSLog(@"in textFieldShouldReturn"); 
    [TextField resignFirstResponder]; 
    return YES; 
} 

- (void)dealloc { 
    [super dealloc]; 
} 

@end 

그것을 사용하고 슬라이드 아웃의 배경 색상을 변경할 수 있습니다. 원하는 경우 UIButton을 사용자 정의하고 사용자 정의 색상을 사용하여 코드를 사용할 수 있습니다. 건배

0

키 윈도우 만 키보드 알림을 수신하므로 텍스트 윈도우를 키 윈도우에 추가해야합니다.

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 28, 320, 150)]; 
// Configure your textField here: 

UIWindow *appWindow = [UIApplication sharedApplication].keyWindow; 
[appWindow addSubview:textField]; 
관련 문제