2013-03-06 105 views
0

我有一些困難找出最佳方式來讓我的uitextfields不會隱藏當鍵盤彈出。現在我有一個包含uitableview子視圖和按鈕的UIView。uitviewcontroller與uitableview和自定義uitablextfields uitablextfields與uitextfields向上/向下滾動鍵盤

* uview中的tableview實際上是一個uiviewcontroller,它帶有一個編程創建的tableivew,所以它不受uitableviewcontroller控制。

我已經完成了研究,我認爲我需要一個滾動視圖,然後將視圖添加到滾動視圖,並在選擇特定文本框並使用鍵盤向上滾動時隱藏某些滾動。

這是一個很好的方法嗎?

UPDATE:

我有兩個單獨的Viewcontrollers。例如讓我們說MainViewcontroller和SecondViewcontroller。第二個viewcontroller有一個可用的視圖。表格視圖內的單元格具有存儲用戶信息的文本框(如表單)。然後我在mainviewcontroller裏面創建了secondviewcontroller的一個對象。我這樣做了,因爲我需要在視圖底部有一個「下一個按鈕」。當我選擇一個字段時,它將位於鍵盤下方,當它彈出時,我想讓它向上滾動,當它關閉時它會下降。我不得不使用uitableview的一個對象,因爲Mainviewcontroller類會變得很大(如果我錯了,請糾正我)。謝謝回覆。

這裏就是我試圖做... 充分的UIView的截圖:開放http://postimage.org/image/puzdwpj3t/ 隨着鍵盤:http://postimage.org/image/g5nkwzwpd/

//下面是一些代碼: 1.這裏的第一類是如SecondViewcontroller。 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: [email protected]"; 
    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._%+-][email protected][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束:(一個NSBundle *)nibBundleOrNil { 自我= [超級initWithNibName:nibNameOrNil束: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)]; 
    
    [email protected]"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 
    
+0

請添加一些代碼。 – MishieMoo 2013-03-06 20:07:53

+0

我已經添加了一些代碼,謝謝! – AppsGuy24 2013-03-08 14:55:57

回答

0

您已經添加泰伯維內部視圖的UIViewController。對?

在哪個視圖中添加了UITextview。? UIViewController視圖?

您可以在UIView中添加UITextView,並通過應用動畫改變UITextView的框架。

Ex。

//以查看UP ....

[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的。

相關問題