本文介绍了如何在UIAextField中的UITextField中启用文本输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIActionsheet中创建textField,但我无法输入文字,任何人都可以对它有所了解????

I am creating textField in UIActionsheet, but I can't input text, can any one has idea about it ????

我的编码如下

-(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];        
}


推荐答案

Hey Veer,有一个你应该在这里采取略微不同的方法。这是我的建议。

Hey Veer, There is a slightly different approach that you should be taking here. Here is what I propose.

.h文件代码

#import <UIKit/UIKit.h>

    @interface trialViewController : UIViewController <UIActionSheetDelegate, UITextFieldDelegate> {

        UITextField *TextField;

    }

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

.m code

#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

使用它并更改背景滑出的颜色。如果您愿意,我可以提供自定义UIButtons的代码,并为您创建自定义颜色。干杯

Use it and change the background color of the slideout. If you want I can give a codes that customize your UIButtons and create Custom colors for you to be used. Cheers

这篇关于如何在UIAextField中的UITextField中启用文本输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 12:12