2014-01-06 45 views
0

我有一個自定義UITableViewCells的UITableView,每個都有兩個UITextFields。當我在打開的視圖中選擇一個UITextField,即不滾動時,在打開的視圖中選擇一個UITextField。它成爲FirstReasponder,我可以輸入文本,因爲我打開在打開的視圖中輸入所有UITextFields可以成爲FirstReasponder,但是當我到達該開放視圖的UITableViewCells的末尾,並嘗試加載當前不可見的下一個UITableViewCell並將其設置爲UITextField成爲第一個應答者dosnt的工作。UItextField becomeFirstReasponder返回否

我在textFieldShouldReturn中設置了一個if語句,它確認textField返回NO成爲FirstReasponder。

我想知道如何解決這個問題,我一直在這個問題上停留了一段時間,並尋找解決方案,但還沒有找到符合我的情況的任何東西。下面是我使用的UITextFieldDelegates,因爲我認爲在這裏我應該做一些像調用或加載下一個UITableViewCell的東西,但我不知道如何。

#pragma mark - Textfield Delegates 
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField 
{ 
    [textField resignFirstResponder]; 

    if ([textField isEqual:cell.widthTexField]) { 
     nWidth = [[sortedItemsArray objectAtIndex:textField.tag] valueForKey:@"w_MM"]; 
    } else if ([textField isEqual:cell.heightTextField]) { 
     nHeight = [[sortedItemsArray objectAtIndex:textField.tag] valueForKey:@"h_MM"]; 
    } 
    return YES; 
} 

-(BOOL)textFieldShouldBeginEditing:(UITextField*)textfield { 

     int height = self.finishingTableView.frame.size.height; 
     NSLog(@"%i", height); 
     self.finishingTableView.frame= CGRectMake(self.finishingTableView.frame.origin.x, self.finishingTableView.frame.origin.y, self.finishingTableView.frame.size.width, 307); 

    // select correct row 
    if (textfield.tag > 999999) { 
     int adjustTag = textfield.tag-1000000; // remove a million so that you have the text fields correct position in the table. (this is only for height textfields) 
     NSIndexPath *indexPath =[NSIndexPath indexPathForRow:adjustTag inSection:0]; 
     [finishingTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
     [self tableView:finishingTableView didSelectRowAtIndexPath:indexPath]; 
     [self.finishingTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES]; 
     return YES; 
    } else { 
     NSIndexPath *indexPath =[NSIndexPath indexPathForRow:textfield.tag inSection:0]; 
     [finishingTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
     [self tableView:finishingTableView didSelectRowAtIndexPath:indexPath]; 
     [self.finishingTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES]; 
     return YES; 
    } 
    return YES; 
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    NSLog(@"%i", textField.tag+1); 
    [[self.view viewWithTag:textField.tag+1] becomeFirstResponder]; 

    BOOL success = [[self.view viewWithTag:textField.tag+1] becomeFirstResponder]; 
    if (success) { 
     NSLog(@"HypnosisView became the first responder"); 
    } else { 
     NSLog(@"Could not become first responder"); 
    } 

    // this means there has been a change in the UItextfield 


    NSLog(@"%@", selectedItemDictionary); 
    if (textField.tag < 999999) { 
     tempFinishingObjectDictionary = [selectedItemDictionary mutableCopy]; 
     if (![textField.text isEqualToString:[selectedItemDictionary objectForKey:@"w_MM"]]) { 
      tempUpdatedRow = @"T"; 
      // remove kevalues 
      [tempFinishingObjectDictionary removeObjectForKey:@"updatedRow"]; 
      [tempFinishingObjectDictionary removeObjectForKey:@"new_w_MM"]; 
      // update keyvalues 
      [tempFinishingObjectDictionary setValue:tempUpdatedRow forKey:@"updatedRow"]; 
      [tempFinishingObjectDictionary setValue:textField.text forKey:@"new_w_MM"]; 
     } 
    } else { 
     if (![textField.text isEqualToString:[selectedItemDictionary objectForKey:@"h_MM"]]) { 
      tempUpdatedRow = @"T"; 
      // remove kevalues 
      [tempFinishingObjectDictionary removeObjectForKey:@"updatedRow"]; 
      [tempFinishingObjectDictionary removeObjectForKey:@"new_h_MM"]; 
      // update keyvalues 
      [tempFinishingObjectDictionary setValue:tempUpdatedRow forKey:@"updatedRow"]; 
      [tempFinishingObjectDictionary setValue:textField.text forKey:@"new_h_MM"]; 
     } 
    } 
    NSLog(@"%@", tempFinishingObjectDictionary); 
    [coreDataController editSelectedFinishing:htmlProjID UpdatedNSD:tempFinishingObjectDictionary SelectedRow:selectedItemIndexPathRow]; 
    [SVProgressHUD dismiss]; 


    NSLog(@"%@", selectedItemDictionary); 

    return YES; 
} 

任何幫助將超級讚賞,因爲我真的堅持這一點。

回答

0

在你的textFieldShouldReturn當你轉到下一個單元格時,你應該檢查兩個單元格是否離開屏幕(因此不存在)。如果是當且僅當屏幕上,你應該通過一個細胞

[tableview setContentOffset:CGPointMake(tableview.contentOffset.x,tableview.contentOffset.y + cellHeight) animated:YES]; 

您將有此滾動調整自己的喜好,因爲我不知道你的應用程序如何流動滾動表。

+0

沒關係只是現在執行會讓你知道我是如何去的。我在CGPointMake上遇到了一個「問題」,並在修復它之前添加了一個「[」。 – HurkNburkS

+0

由於某種原因,這不是爲我滾動。我已經把它放到我的becomeFirstReasponder中,如果在textFieldShouldReturn裏面聲明,那麼如果textfield是NULL,那麼我打算執行你給我的代碼行。但由於某種原因,它不會爲我滾動。我把cellHeight設置爲84,所以我會注意到它過多滾動,但它dosnt。 – HurkNburkS

相關問題