0

キーボードが飛び出したときにuitextfieldを非表示にしないための最良の方法を見つけるのに苦労しています。現在、uitableviewサブビューとボタンを含むUIViewがあります。

* uiview内にあるtableviewは、実際にはプログラムで作成されたtableivewを備えたuiviewcontrollerであるため、uitableviewcontrollerによって制御されません。

私は調査を行いましたが、スクロールビューが必要だと思います。次に、ビューをスクロールビューに追加し、特定のテキストフィールドが選択され、キーボードを上に向けて非表示になっているときに、スクロールを操作します。

これは良いアプローチですか?

アップデート:

私は2つの別々のビューコントローラーを持っています。たとえば、MainViewcontrollerとSecondViewcontrollerとしましょう。secondviewcontrollerにはuitableviewが含まれています。テーブルビュー内のセルには、ユーザー情報(フォームなど)を格納するテキストボックスがあります。次に、mainviewcontroller内にsecondviewcontrollerのオブジェクトを作成しました。ビューの下部に「次へボタン」が必要なため、これを行いました。ポップアップ時にキーボードの下に配置されるフィールドを選択すると、上にスクロールして閉じたときに下に移動します。Mainviewcontrollerクラスは非常に大きいため、uitableviewのオブジェクトを使用する必要がありました(間違っている場合は修正してください)。返信いただきありがとうございます。

これが私がやろうとしていることのスクリーンショットです...フルUIView:http://postimage.org/image/puzdwpj3t/キーボード を開いた状態: http: //postimage.org/image/g5nkwzwpd/

//ここにいくつかのコードがあります:1。ここでの最初のクラスは例えばSecondViewcontrollerです。2.コードの2番目のセクションは、たとえばmainviewcontrollerであり、secondviewcontrollerのオブジェクトを作成します。

  1. 以下のuiviewcontrollerは、3つのセクションを持つテーブルを作成します。各セルにはテキストフィールドがあります(中央を除いて、uipickerviewを表示するボタンです)。これは完全なクラスではありません。テーブルが作成された領域のみを取得しました。

    -(void)viewDidLoad{
    [super viewDidLoad];
    
    
    
    
    //    scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 300, 500)];
    //    scrollview.pagingEnabled = YES;
    //    
    //    //[scrollview addSubview:self.view];
    //    [self.view addSubview:scrollview];
    
    
    
    table.scrollEnabled = YES;
    dataArray = [[NSMutableArray alloc] init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 290, 30)];
    
    //dropper
    titleField = [[UITextField alloc] initWithFrame:CGRectMake(10, 2, 300, 30)];
    titleField.layer.cornerRadius = 8;
    titleField.backgroundColor = [UIColor clearColor];
    
    NSArray *firstItemsArray = [[NSArray alloc] initWithObjects:@"1",@"2", nil];
    
    NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:firstItemsArray forKey:@"data"];
    [dataArray addObject:firstItemsArrayDict];
    
    
    //Second section dat
    NSArray *secondItemsArray = [[NSArray alloc] initWithObjects:@"1", nil];
    NSDictionary *secondItemsArrayDict = [NSDictionary dictionaryWithObject:secondItemsArray forKey:@"data"];
    [dataArray addObject:secondItemsArrayDict];
    
    
    NSArray *thirdItemsArray = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
    NSDictionary *thirdItemsArrayDict = [NSDictionary dictionaryWithObject:thirdItemsArray forKey:@"data"];
    [dataArray addObject:thirdItemsArrayDict];
    
    NSLog(@"the dataArray%@",dataArray);
    
    
    if([self connectedToNetwork]){
    
    dispatch_async(kBgQueue, ^{
    
    //build the url of strings
    FULLURL = [SERVERNAME stringByAppendingFormat:TitleLink];
    //create the url
    NSURL *url = [[NSURL alloc] initWithString:FULLURL];
    //NSLog(@"here title url%@",url);
    
    //get the data from the url
    NSData* data = [NSData dataWithContentsOfURL: url];
    //NSLog(@"here%@",data);
    
    //get the data from the url
    [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
    // NSLog(@"titleid:%@",TITLEID);
    // NSLog(@"title categories:%@",titlecategories);
    
    });
    
    [table setBounces:NO];
    
    
    }else{
    
    
    dispatch_async(dispatch_get_main_queue(), ^ {
    UIAlertView *alert = [[UIAlertView alloc]
          initWithTitle: @"Please Check your internet connection"
          message:@"Enable your internet connection"
          delegate: nil
          cancelButtonTitle:@"OK"
          otherButtonTitles:nil];
    [alert show];
    });
    }
    
    }
    
    -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
    {
    return [dataArray count];
    }
    
    
    -(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
    {
    //Number of rows it should expect should be based on the section
    NSDictionary *dictionary = [dataArray objectAtIndex:section];
    NSArray *array = [dictionary objectForKey:@"data"];
    return [array count];
    
    }
    
    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(indexPath.section == 1){
    cell.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"longdropper300.png"]];
    
    }
    else{
    cell.backgroundColor = [UIColor whiteColor];
    }
    }
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    textField = [[UITextField alloc] initWithFrame:CGRectMake(15, 10, 290, 30)];
    
    
    static NSString *cellValue = @"Cell";
    UITableViewCell *cell =nil;
    
    if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellValue];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    
    if ([indexPath section] == 0) {
    
    //cellValue=[items objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle= UITableViewCellSelectionStyleNone;
    //textField.tag = 1;
    textField.adjustsFontSizeToFitWidth = YES;
    textField.textColor = [UIColor blackColor];
    
    if(indexPath.section == 0){
    //textfield for email
    if ([indexPath row] == 0) {
    textField.tag = 1;
    textField.text = EMAIL;
    textField.textColor= [UIColor blackColor];
    textField.placeholder = @"Email: example@gmail.com";
    textField.keyboardType = UIKeyboardTypeEmailAddress;
    textField.returnKeyType = UIReturnKeyNext;
    
    }
    //textfield for phone number
    else {
    textField.tag = 2;
    if ([PHONENUMBER isEqual: [NSNull null]] && PHONENUMBER == nil && PHONENUMBER == NULL && [PHONENUMBER isEqual: @""]){
    NSLog(@"phone is empty%@",PHONENUMBER);
    //[PHONENUMBER isEqual:@"frank"];
    
    }else{
    NSLog(@"phone is not empty%@",PHONENUMBER);
    textField.text = PHONENUMBER;
    }
    
    textField.placeholder = @"Phone: xxx-xxx-xxxx";
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyDone;
    textField.secureTextEntry = NO;
    }
    textField.backgroundColor = [UIColor whiteColor];
    textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
    textField.textAlignment = UITextAlignmentLeft;
    textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
    [textField setEnabled: YES];
    textField.delegate = self;
    [cell addSubview:textField];
    
    }
    }
    if(indexPath.section == 1){
    
    [titleField setTextColor:[UIColor whiteColor]];
    titleField.tag = 3;
    titleField.placeholder = @"Select Contact Title";
    titleField.returnKeyType = UIReturnKeyNext;
    
    //titleField == textField.tag = 3;
    if ([TITLENAME isEqual: [NSNull null]]){
    NSLog(@"titlename is empty%@",TITLENAME);
    
    }else{
    NSLog(@"titlename is not empty%@",TITLENAME);
    titleField.text = TITLENAME;
    }
    
    
    titleField.keyboardType = UIKeyboardTypeDefault;
    titleField.returnKeyType = UIReturnKeyDone;
    titleField.secureTextEntry = NO;
    titleField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
    titleField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
    titleField.textAlignment = UITextAlignmentCenter;
    titleField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
    [titleField setEnabled: NO];
    titleField.delegate = self;
    
    [cell addSubview:titleField];
    
    
    NSLog(@"here is the titlename%@",TITLENAME);
    
    }
    
    if(indexPath.section == 2){
    
    if ([indexPath row] == 0) {
    
    textField.tag = 4;
    textField.placeholder = @"First Name";
    cell.selectionStyle= UITableViewCellSelectionStyleNone;
    
    if ([FIRSTNAME isEqual: [NSNull null]]){
    NSLog(@"firstname is empty%@",FIRSTNAME);
    textField.text = @"";
    
    }else{
    
    textField.text = FIRSTNAME;
    
    }
    
    textField.keyboardType = UIKeyboardTypeEmailAddress;
    textField.returnKeyType = UIReturnKeyNext;
    }
    
    if([indexPath row] == 1){
    textField.tag = 5;
    textField.placeholder = @"Last Name";
    
    
    if ([LASTNAME isEqual: [NSNull null]]){
    NSLog(@"lastname is empty%@",LASTNAME);
    textField.text = @"";
    
    }else{
    textField.text = LASTNAME;
    
    
    }
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyNext;
    //textField.secureTextEntry = NO;
    
    }
    
    if([indexPath row] == 2){
    
    textField.tag = 6;
    textField.placeholder = @"Company";
    
    if ([COMPANY isEqual: [NSNull null]]){
    NSLog(@"company is empty%@",COMPANY);
    textField.text = @"";
    }
    else{
    textField.text = COMPANY;
    }
    
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyDone;
    textField.secureTextEntry = NO;
    
    
    }
    
    //]textField.backgroundColor = [UIColor whiteColor];
    textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
    textField.textAlignment = UITextAlignmentLeft;
    textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
    [textField setEnabled: YES];
    textField.delegate = self;
    [cell addSubview:textField];
    
    }
    
    return cell;
    }
    
    //Change the Height of title cell drop down
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
    {
    if (indexPath.section == 1) {
    if (indexPath.row == 0) {
    return 30;
    }
    }
    return 45;
    }
    
    
    
    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    
    if(([textField tag] == 1)){
    
    NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
    //Valid email address
    
    if ([emailTest evaluateWithObject:textField.text] == YES)
    {
    
    EMAIL = [textField.text copy];
    NSLog(@"here is the email%@",EMAIL);
    }
    else
    {
    
    UIAlertView *alert = [[UIAlertView alloc]
    
                  initWithTitle: @"Bad Email"
                  message: @"Please Re-enter the email address with a valid email"
                  delegate: nil
                  cancelButtonTitle:@"OK"
                  otherButtonTitles:nil];
    [alert show];
    textField.text =  nil;
    NSLog(@"email not in proper format");
    }
    
    }
    
    if(([textField tag] == 2)){
    
    NSString *phoneRegex = @"[235689][0-9]{6}([0-9]{3})?";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
    //valid email address
    
    if ([phoneTest evaluateWithObject:textField.text] == YES)
    {
    
    PHONENUMBER = [textField.text copy];
    NSLog(@"here is the phone number %@",PHONENUMBER);
    }
    else
    {
    NSLog(@"Phone Number Invalid");
    UIAlertView *alert = [[UIAlertView alloc]
                  initWithTitle: @"xxx-xxx-xxxx"
                  message: @"Please enter a valid phone number"
                  delegate: nil
                  cancelButtonTitle:@"OK"
                  otherButtonTitles:nil];
    [alert show];
    textField.text =  nil;
    }
    }
    
    if(([textField tag] == 4)){
    
    
    FIRSTNAME = [textField.text copy];
    NSLog(@"here is the firstName%@",FIRSTNAME);
    }
    if(([textField tag] == 5)){
    
    
    LASTNAME = [textField.text copy];
    NSLog(@"here is the Last Name%@",LASTNAME);
    }
    
    if(([textField tag] == 6)){
    
    COMPANY = [textField.text copy];
    NSLog(@"here is the Company%@",COMPANY);
    }
    
    
    
    
    return YES;
    }
    
    -(BOOL)textFieldShouldReturn:(UITextField*)textField;
    {
    NSInteger nextTag = textField.tag + 1;
    // Try to find next responder
    UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
    if (nextResponder) {
    
    // Found next responder, so set it.
    [nextResponder becomeFirstResponder];
    } else {
    // Not found, so remove keyboard.
    [textField resignFirstResponder];
    }
    return NO; // We do not want UITextField to insert line-breaks.
    }
    
  2. メインビューコントローラー-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if(self){//カスタム初期化} return self; }

    - (void)addMyButton{    // Method for creating button, with background image and other properties
    
    loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    loginButton.frame = CGRectMake(10.0,130.0, 300.0, 40.0);
    [loginButton setTitle:@"Login" forState:UIControlStateNormal];
    loginButton.backgroundColor = [UIColor clearColor];
    [loginButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ];
    UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];
    UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [loginButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
    UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"];
    UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [loginButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
    [self.view addSubview:loginButton];
    [loginButton addTarget: self
    action: @selector(loginButtonClicked:)
    forControlEvents: UIControlEventTouchUpInside];
    }
    
    //Change the View and send the information to the servlet once login is clicked.
    - (void)loginButtonClicked: (id)sender{
    
    loginButton.enabled = NO;
    activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 60, 20, 20)];
    UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
    [self navigationItem].rightBarButtonItem = barButton;
    [activityIndicator startAnimating];
    
    [passwordTF resignFirstResponder];
    
    
    
    //start new thread
    //dispatch_async(kBgQueue, ^{
    NSLog(@"Username:%@",USERNAME);
    NSLog(@"Password:%@",PASSWORD);
    NSLog(@"COMPANYID: %@", COMPANYID);
    //NSLog(@"LOGINID: %@", LOGINID);
    
    if((USERNAME == NULL) || (USERNAME == nil) || ([USERNAME isEqualToString:@""])){
    //NSLog(@"null password or usernaem");
    UIAlertView *alert = [[UIAlertView alloc]
              initWithTitle: @"Username or password not found"
              message:@"please try again"
              delegate: nil
              cancelButtonTitle:@"OK"
              otherButtonTitles:nil];
    [alert show];
    [activityIndicator stopAnimating];
    
    // MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
    // [self.navigationController pushViewController:SenderInfoViews animated:NO];
    
    }else if((PASSWORD == NULL) || (PASSWORD == nil) || ([PASSWORD isEqualToString:@""])){
    //NSLog(@"null password or usernaem");
    
    UIAlertView *alert = [[UIAlertView alloc]
              initWithTitle: @"Username or password not found"
              message:@"please try again"
              delegate: nil
              cancelButtonTitle:@"OK"
              otherButtonTitles:nil];
    [alert show];
    [activityIndicator stopAnimating];
    
    // MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
    // [self.navigationController pushViewController:SenderInfoViews animated:NO];
    
    }else{
    //NSLog(@"all good");
    
    NSLog(@"Login button clicked, load the next view and check for password");
    NSLog(@"full the url%@",FULLURL);
    //build the url of strings
    FULLURL = ******
    
    
    if([self connectedToNetwork])
    
    {
    dispatch_queue_t downloadQueue = dispatch_queue_create("data loader", NULL);
    
    dispatch_async(downloadQueue, ^{
    
    //create the url
    NSURL *url = [[NSURL alloc] initWithString:FULLURL];
    NSLog(@"here%@",url);
    
    //get the data from the url
    NSData* data = [NSData dataWithContentsOfURL: url];
    NSLog(@"here%@",data);
    
    NSLog(@"here that data%@",data);
    
    if(data != nil){
    //
    //get the data from the url
    
    [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
    //
    NSLog(@"hello Username:%@",USERNAME);
    NSLog(@"Password:%@",PASSWORD);
    NSLog(@"h4llo COMPANYID: %@", COMPANYID);
    NSLog(@"LOGINID: %@", LOGINID);
    
    //
    //       // [self performSelectorOnMainThread:@selector(checkLogin:) withObject:LOGINID waitUntilDone:YES];
    //
    //
    @try {
    //NSLog(@"before loginddd %@",LOGINID);
    if(COMPANYID != 0){
    
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
        [prefs setObject:USERNAME forKey:@"UserName"];
        [prefs setObject:@"Pass" forKey:@"Pass"];
        // This is suggested to synch prefs, but is not needed
        [prefs synchronize];
    
        NSLog(@"here is the login identiy%@",LOGINID);
        MangoContactSelection *SenderInfoViews = [[MangoContactSelection alloc] init];
        [self.navigationController pushViewController:SenderInfoViews animated:NO];
    
    
    
    }
    else{
        dispatch_async(dispatch_get_main_queue(), ^ {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"bad NAME"
                              message:@"GOO"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];
    
    //                        [self.view setNeedsDisplay];
        [self.view reloadInputViews];
        MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
        [self.navigationController pushViewController:SenderInfoViews animated:NO];
            [activityIndicator stopAnimating];
        });
    }
    }
    @catch (NSException * e) {
    NSLog(@"Exception: %@", e);
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"Login Failed"
                          message:@"Bad"
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [alert show];
    //[activityIndicator stopAnimating];
    }
    
    // if the data is nil do this
    }else{
    dispatch_async(dispatch_get_main_queue(), ^ {
    UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle: @"No Internet!"
                      message:@"Please Check your internet Connection"
                      delegate: nil
                      cancelButtonTitle:@"OK"
                      otherButtonTitles:nil];
    [alert show];
    [self.view setNeedsDisplay];
    MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
    [self.navigationController pushViewController:SenderInfoViews animated:NO];
    });
    }
    
    dispatch_async(dispatch_get_main_queue(), ^ {
    
    //UIImage *image = [UIImage imageWithData:imageData];
    
    //[table reloadData];
    //[actIndicator stopAnimating];
    [self.view reloadInputViews];
    [activityIndicator stopAnimating];
    
    // sender because that's the element that called us by clicking refresh
    
    });
    
    });
    
    
    }else{
    
    UIAlertView *alert = [[UIAlertView alloc]
                  initWithTitle: @"No Internet!"
                  message:@"Please Check your internet Connection"
                  delegate: nil
                  cancelButtonTitle:@"OK"
                  otherButtonTitles:nil];
    [alert show];
    [self.view setNeedsDisplay];
    MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
    [self.navigationController pushViewController:SenderInfoViews animated:NO];
    }
    }
    [self.view reloadInputViews];
    }//login
    
    -(void)gobacktoContactCreate{
    MangoContactSelection *gobackhome = [[MangoContactSelection alloc]init];
    [self.navigationController pushViewController:gobackhome animated:YES];
    
    }
    
    - (void)viewDidLoad
    {
    
    [super viewDidLoad];
    //self.view setBackgroundColor:([UIColor blackColor]);
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSString *userName = [prefs stringForKey:@"UserName"];
    //NSString *pass = [prefs stringForKey:@"Pass"];
    
    //navigation bar
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    [self.navigationController setNavigationBarHidden: NO animated:NO];
    self.navigationItem.hidesBackButton = YES;
    
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:@selector(gobacktoContactCreate)];
    
    self.navigationItem.title=@"Login";
    
    //User name text field................
    usernameTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 25, 300, 40)];
    usernameTF.borderStyle = UITextBorderStyleRoundedRect;
    usernameTF.font = [UIFont systemFontOfSize:15];
    usernameTF.placeholder = @"Username";
    usernameTF.text = userName;
    usernameTF.autocorrectionType = UITextAutocorrectionTypeNo;
    usernameTF.keyboardType = UIKeyboardTypeDefault;
    usernameTF.returnKeyType = UIReturnKeyNext;
    usernameTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    usernameTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    
    
    
    //User name text field................
    passwordTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 75, 300, 40)];
    passwordTF.borderStyle = UITextBorderStyleRoundedRect;
    passwordTF.font = [UIFont systemFontOfSize:15];
    passwordTF.placeholder = @"Password";
    passwordTF.autocorrectionType = UITextAutocorrectionTypeNo;
    passwordTF.keyboardType = UIKeyboardTypeDefault;
    passwordTF.returnKeyType = UIReturnKeyDone;
    passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    passwordTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    passwordTF.secureTextEntry = YES;
    
    //create the clickable labels
    //register link
    registerLabel = [[UILabel alloc]initWithFrame:CGRectMake(150,170, 150, 20)];
    registerLabel.text = @"Request an account";
    registerLabel.font = [UIFont systemFontOfSize:12];
    registerLabel.userInteractionEnabled = YES;
    registerLabel.textColor = [UIColor blueColor];
    UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestRegistration:)];
    [registerLabel addGestureRecognizer:gr];
    gr.numberOfTapsRequired = 1;
    gr.cancelsTouchesInView = NO;
    
    //create the label for
    registerText = [[UILabel alloc]initWithFrame:CGRectMake(60,170, 90, 20)];
    registerText.text = @"New to *******?";
    registerText.font = [UIFont systemFontOfSize:12];
    
    //    //forgot password link
    //    forgotPassword = [[UILabel alloc]initWithFrame:CGRectMake(210,190, 150, 20)];
    //    forgotPassword.font = [UIFont systemFontOfSize:12];
    //    forgotPassword.textColor = [UIColor blueColor];
    //    forgotPassword.text = @"Forgot Password?";
    //    forgotPassword.userInteractionEnabled = YES;
    //    UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestForgottenPassword:)];
    //    [registerLabel addGestureRecognizer:tapRec];
    //    tapRec.numberOfTapsRequired = 1;
    //    tapRec.cancelsTouchesInView = NO;
    
    [self.view addSubview:passwordTF];
    [self.view addSubview:usernameTF];
    [self.view addSubview:registerLabel];
    [self.view addSubview:registerText];
    
    //    [self.view addSubview:forgotPassword];
    
    [self addMyButton];
    
    usernameTF.delegate = self;
    passwordTF.delegate = self;
    
    }
    
    -(void)requestRegistration:(UITapGestureRecognizer *)gr{
    
    //for registration
    NSLog(@"request registration link clicked");
    
    }
    
    
    -(void)requestNewPassword:(UITapGestureRecognizer *)tapRec{
    
    //for registration
    NSLog(@"request password link clicked");
    }
    
    
    
    //Grabs the Json from the servlet and then parses it for the username and password.
    
    - (void)fetchedData:(NSData *)responseData {
    //parse out the json data
    
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
                                         options:kNilOptions
                                           error:&error];
    
    //NSLog(@"here is the login info from json: %@", json);
    // NSString *FALSELOGIN;
    
    
    COMPANYID = [json valueForKey:@"companyid"];
    NSLog(@"COMPANY ID: %@", COMPANYID);
    
    // LOGINID = [json valueForKey:@"login"];
    // NSLog(@"LOGIN ID: %@", LOGINID);
    
    }
    
    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    
    if((textField = usernameTF)){
    USERNAME = [textField.text copy];
    //NSLog(@"here is the string for username;%@", USERNAME);
    }
    
    if((textField = passwordTF)){
    PASSWORD = [textField.text copy];
    
    //NSLog(@"here is the password guy %@",PASSWORD);
    
    }
    
    return YES;
    }
    
    
    
    
    -(BOOL)textFieldShouldReturn:(UITextField *)textField
    {
    if (textField == usernameTF) {
    [passwordTF becomeFirstResponder];
    }
    else{
    [passwordTF resignFirstResponder];
    }
    return YES;
    }
    
    
    //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    //{
    //    [passwordTF resignFirstResponder];
    //
    //}
    
    - (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }
    
    @end
    
4

2 に答える 2

0

UIViewControllerのビュー内にTableviewを追加しました。右?

UITextviewを追加したビューはどれですか。UIViewControllerのビュー??

UIViewにUITextViewを追加し、アニメーションを適用することで、UITextViewのフレームを変更するだけです。

元。

//ビューアップ...

[UIView animationWithDuration:secs delay:0.0 option:option animation:^{

    CGRect frame = textview.frame;
    frame.origin.y = 10; // Change Y position of frame.
    textview.frame = frame;

}
completion:nil];

//ビューを削除します

[UIView animationWithDuration:secs delay:0.0 option:option animation:^{

    CGRect frame = textview.frame;
    frame.origin.y = 100; // Change Y position of frame.
    textview.frame = frame;

}
completion:nil];

UIScrollViewを使用する必要はありません。

于 2013-03-06T18:32:36.733 に答える
0

Dhaval、私はあなたの解決策がうまくいくと信じています、しかし私はここで私が探していたものを正確に見つけることになりました:

http://www.youtube.com/watch?feature=player_detailpage&v=qSvDWnasJ9I

ありがとう。

于 2013-03-15T14:40:59.180 に答える