2011-11-25 2 views
0

많은 시행 착오 끝에 나는 포기하고 질문하고 있습니다. 나는 비슷한 문제를 가진 많은 사람들을 보았지만 모든 해답을 올바르게 얻을 수는 없습니다.UItextView 및 애니메이션이있는 UItableView?

저는 35 개의 텍스트 파일로 된 UITableView를 가지고 있습니다.

UITableView의 아래쪽에있는 셀을 스크롤하고 편집하려고하면 키보드 위의 셀이 제대로 배치되지 않습니다.

저는보기 크기의 변경 등에 대한 많은 답변을 보았습니다. 그러나 그 중 아무도 지금까지 제대로 작동하지 않았습니다.

누구나 구체적인 코드 예제를 사용하여 "올바른"방법을 명확히 할 수 있습니까? 당신은 키보드 위의 낮은 텍스트 필드를 스크롤 할 수 있도록 스크롤 뷰 키가 만들 필요가

#import "EditProfilePage.h" 


@implementation EditProfilePage 
#define kOFFSET_FOR_KEYBOARD 70.0 


static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3; 
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216; 

static const CGFloat CELL_HEIGHT = 44; 

static const CGFloat TOOLBAR_HEIGHT = 44; 
static const CGFloat WINDOW_MINUS_TOOLBAR_HEIGHT_PORTRAIT = 460; 



@synthesize scrollView,tableContents,txtField,allTextField,tableView; 

@synthesize txtUserName ,txtFirstName ,txtLastName ,txtNickName,txtDisplayName,txtEmail,txtWebSite,txtAboutMe ,txtNewPassword ,txtPasswordAgain,btnSubmit ; 

//extended profile information 
@synthesize txtPayPalEmail ,txtActiveMemPk ,txtMemPkExpireDate,lbl,textFieldBeingEdited; 

//business profile information 
@synthesize txtBusinessName ,txtAbnAcn ,txtContactName ,txtPhone ,txtFax ,txtMobile ,txtBusinessEmail ,txtFacebookLink ,txtLinkedinLink ,txtMySpaceLink; 
@synthesize txtBlogLink ,txtInstanMessage ,txtWebsite ,txtStreet ,txtCitySuburb ,txtZipCode ,txtState ,txtTradingHour; 
@synthesize txtActiveOfService ,txtTradeOnWeekend ,txtProduct , txtService ,txtPickUpAndDelivery; 




- (void)viewDidLoad 
{ 

    [super viewDidLoad]; 

    allTextField=[[NSMutableArray alloc] initWithObjects:@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",nil]; 

    [self.scrollView setContentSize:CGSizeMake(320, (CELL_HEIGHT * [self.allTextField count]))]; 
    ![enter image description here][1][self.tableView setFrame:CGRectMake(0, 0,320, (CELL_HEIGHT * [self.allTextField count]))]; 



} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    [[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(keyboardWillShow:) 
    name:UIKeyboardWillShowNotification 
    object:nil]; 

    [[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(keyboardWillHide:) 
    name:UIKeyboardWillHideNotification 
    object:nil]; 

    self.navigationController.navigationBarHidden=YES; 
} 
// 
-(void)viewWillDisappear:(BOOL)animated 
{ 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; 
     //self.navigationController.navigationBarHidden=NO; 
} 


-(void) keyboardWillShow:(NSNotification *)note 
{ 
    CGRect keyboardBounds; 
    [[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &keyboardBounds]; 
    // keyboardHeight = keyboardBounds.size.height; 
// if (keyboardIsShowing == NO) 
    { 
     //keyboardIsShowing = YES; 
//  CGRect frame = self.view.frame; 
//  frame.size.height -= keyboardHeight; 

     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 
     [UIView setAnimationDuration:0.3f]; 
     //self.view.frame = frame; 
     [UIView commitAnimations]; 
    } 
} 

- (void) textFieldDidBeginEditing:(UITextField *)textField 
{ 
    CGRect frame = textField.frame; 
    CGFloat rowHeight = self.tableView.rowHeight; 
    if (textField == txtUserName.tag) 
    { 
     frame.origin.y += rowHeight * txtUserName.tag; 
    } 
    // else if (textField == textFields[CELL_FIELD_TWO]) 
// { 
//  frame.origin.y += rowHeight * CELL_FIELD_TWO; 
// } 
// else if (textField == textFields[CELL_FIELD_THREE]) 
// { 
//  frame.origin.y += rowHeight * CELL_FIELD_THREE; 
// } 
// else if (textField == textFields[CELL_FIELD_FOUR]) 
// { 
//  frame.origin.y += rowHeight * CELL_FIELD_FOUR; 
// } 
    CGFloat viewHeight = self.tableView.frame.size.height; 
    CGFloat halfHeight = viewHeight/2; 
    CGFloat midpoint = frame.origin.y + (textField.frame.size.height/2); 
    if (midpoint < halfHeight) 
    { 
     frame.origin.y = 0; 
     frame.size.height = midpoint; 
    } 
    else 
    { 
     frame.origin.y = midpoint; 
     frame.size.height = midpoint; 
    } 
    [self.tableView scrollRectToVisible:frame animated:YES]; 
} 



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // NSArray *lstData=[self.tableContents objectForKey:[self.txtField objectAtIndex:section]]; 
    // return[lstData count]; 

    return[allTextField count]; 
} 




-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *cellIdentifier [email protected]"Cell"; 


    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell==nil) 
    { 
     cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
     cell.accessoryType=UITableViewCellAccessoryNone; 
     cell.selectionStyle=UITableViewCellSelectionStyleNone; 
     cell.font = [UIFont fontWithName:@"Helvetica" size:14]; 
    } 

    if ([indexPath row]==0) 
    { 
     txtUserName=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)]; 
     [email protected]"User Name"; 
     //txtUserName.backgroundColor = [UIColor grayColor]; 
     [txtUserName addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; 
     cell.accessoryView=txtUserName; 
     [email protected]"User Name:"; 
     //cell.font = [UIFont fontWithName:@"Helvetica" size:14]; 

     txtUserName.keyboardType = UIKeyboardTypeDefault; 
     txtUserName.returnKeyType = UIReturnKeyDone; 
     txtUserName.clearsOnBeginEditing = NO; 
     txtUserName.textAlignment = UITextAlignmentLeft; 

     // (The tag by indexPath.row is the critical part to identifying the appropriate 
     // row in textFieldDidBeginEditing and textFieldShouldEndEditing below:) 

     txtUserName.tag=indexPath.row; 

     //txtUserName.delegate = self; 

     txtUserName.clearButtonMode = UITextFieldViewModeWhileEditing; 
     [txtUserName setEnabled: YES]; 

     [cell addSubview:txtUserName]; 

     [txtUserName release]; 



     //cell.font = [UIFont fontWithName:@"impact" size:10 line:2]; 

    } 

    if ([indexPath row]==1) 
    { 
     txtFirstName=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)]; 
     [email protected]"First Name"; 
     cell.accessoryView=txtFirstName; 
     [email protected]"First Name:"; 
     //cell.font = [UIFont fontWithName:@"Helvetica" size:14]; 

    } 

    if ([indexPath row]==2) 
    { 
     txtLastName=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)]; 
     [email protected]"Last Name"; 
     cell.accessoryView=txtLastName; 
     [email protected]"Last Name:"; 
     //cell.font = [UIFont fontWithName:@"Helvetica" size:14]; 


    } 

    if ([indexPath row]==3) 
    { 
     txtNickName=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)]; 
     [email protected]"Nick Name"; 
     cell.accessoryView=txtNickName; 
     [email protected]"Nick Name:"; 
     //cell.font = [UIFont fontWithName:@"Helvetica" size:14]; 


    } 

    if ([indexPath row]==4) 
    { 
     txtDisplayName=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)]; 
     [email protected]"Display Name"; 
     cell.accessoryView=txtDisplayName; 
     [email protected]"Display Name:"; 
     //cell.font = [UIFont fontWithName:@"Helvetica" size:14]; 


    } 

    if ([indexPath row]==5) 
    { 
     txtEmail=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)]; 
     [email protected]"Email"; 
     cell.accessoryView=txtEmail; 
     [email protected]"Email ID:"; 
     cell.font = [UIFont fontWithName:@"Helvetica" size:14]; 


    } 



    return cell; 
} 







@end 
+1

당신은 문제가 무엇인지에 대해 더 구체적으로해야합니다

여기에 그것을 수행하는 방법에 대해 설명 기사입니다. 작은 코드 샘플로 문제를 재현 해보십시오. –

+0

나는 tableview 하나에 다른 35 텍스트 필드가 ..... 나는 사용자가 키보드를 통해 texfield를 만질 때까지 텍스트 필드를 이동하고 싶습니다 .... plz 도와주세요 ..... 감사합니다 선생 –

+1

나는 당신을 생각합니다. 문제를 완전히 이해할 수 있도록 스크린 샷을 제공해야합니다. 다시 말씀 드리 자면 문제를 재현 할 수있는 최소의 코드를 얻을 때까지 코드를 줄이고 새 코드와 스크린 샷을 사용하여 질문을 편집하십시오. –

답변

관련 문제