how to enable text input in UITextField which is in UIActionSheet?

后端 未结 2 1992
甜味超标
甜味超标 2020-12-20 01:16

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

my coding is as follow

-(void)commentsMethod: (         


        
相关标签:
2条回答
  • 2020-12-20 01:20

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

    .h file code

    #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
    

    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

    0 讨论(0)
  • 2020-12-20 01:44

    Only key window receives keyboard notifications, so you have to add your textField into the key window.

    UITextField *textField    = [[UITextField alloc] initWithFrame:CGRectMake(0, 28, 320, 150)];
    // Configure your textField here:
    
    UIWindow *appWindow = [UIApplication sharedApplication].keyWindow;
    [appWindow addSubview:textField];
    
    0 讨论(0)
提交回复
热议问题