2009-12-19 3 views
1

사실 저는 textview의 여섯 번째 섹션에 텍스트 필드가 있고 textview.11의 열 번째 섹션에 textview가 있습니다. 여섯 번째 섹션의 texfield를 클릭하면 키보드가 텍스트를 덮습니다. 필드와 똑같은 일이 textview.for에 대해 NSNotificationCenters를 사용하여 발생했습니다. 와 나는 같이 코드를 작성 :textfield 및 textview에 대한 NSNotification 문제

- (무효) viewWillAppear : 애니메이션 (BOOL) {

tableView.tableFooterView=nil; 
[self reloadView]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) 
              name:UIKeyboardWillShowNotification object:self.view.window]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) 
              name:UIKeyboardWillHideNotification object:self.view.window]; 
[tableView reloadData]; 

}

- (무효) setViewMovedUp : (BOOL) movedUp {

[UIView beginAnimations : nil context : NULL]; [UIView setAnimationDuration : 0.5]; // 뷰를 위로 이동하려는 경우 CGRect rect = mview.frame; if (movedUp) {
rect.origin.y = rect.origin.y - kOFFSET_FOR_KEYBOARD; rect.size.height = rect.size.height + kOFFSET_FOR_KEYBOARD; } else { rect.origin.y = rect.origin.y + kOFFSET_FOR_KEYBOARD; rect.size.height = rect.size.height - kOFFSET_FOR_KEYBOARD; } mview.frame = rect;

[UIView commitAnimations]; 

}

  • (무효) keyboardWillShow : (NSNotification *) NOTIF { //의 printf ("\ n 개의 키보드가 표시됩니다"); // 키보드가 표시됩니다. 텍스트 필드가 활성화되어있는 따라 이동하거나, 아래로 이동 적절

    경우 ([notesTextView isFirstResponder] & & mview.frame.origin.y> = 0) {
    [자기 setViewMovedUp : YES]; 한다} else 경우 ([notesTextView isFirstResponder] & & mview.frame.origin.y < 0!) {[자기 setViewMovedUp : NO] 없다 한다} else

    경우 ([wineryTextField isFirstResponder] & & mview.frame.origin.y> = 0) {
    [자기 setViewMovedUp : YES]; 한다} else 경우 ([wineryTextField isFirstResponder] & & mview.frame.origin.y < 0!) {[자기 setViewMovedUp : NO] 없다 }

}

  • (무효) keyboardWillHide : (NSNotification *) NOTIF { //의 printf ("\ n을 키보드 숨길 것이다"); // 키보드가 표시됩니다.텍스트 필드가 활성화되어있는 따라 이동하거나, 아래로 이동 적절

    경우 ([notesTextView isFirstResponder] & & mview.frame.origin.y> = 0) { [자기 setViewMovedUp : YES]; 한다} else 경우 ([notesTextView isFirstResponder] & & mview.frame.origin.y < 0!) {[자기 setViewMovedUp : NO] 없다 한다} else

    경우 ([wineryTextField isFirstResponder] & & mview.frame.origin.y> = 0) { [자기 setViewMovedUp : YES]; 한다} else 경우 ([wineryTextField isFirstResponder] & & mview.frame.origin.y < 0!) {[자기 setViewMovedUp : NO] 없다 }

}

  • (BOOL) 텍스트 뷰 (UITextView *) 텍스트 뷰 shouldChangeTextInRange (NSRange) 범위 replacementText (는 NSString *) 텍스트 { ([텍스트 isEqualToString 경우 : @ "\ n"]) {

    //event.eventNotes = notesTextView.text; 
    
    if(textView==notesTextView) 
    { 
    
        //[self setViewMovedUp:NO]; 
        [textView resignFirstResponder]; 
    } 
    return NO; 
    

    }

    ,

    return 예;

}

  • (BOOL) textFieldShouldReturn (의 UITextField *)에 textField {

    경우 (에 textField == wineryTextField) {[자기 setViewMovedUp : NO] 없다 [wineryTextField resignFirstResponder]; } }

는 위의 내가 스크롤 용으로 작성했던 코드는 문제 view.but 내가 텍스트 필드에 클릭이 가야지으로 happed 된 같은 스크롤 대신 아래로 스크롤 할 때 몇 번하다입니다 textView.the 문제는 다른 컨트롤러로 이동하여 다시 eighter texfield 또는 textview를 클릭했을 때 발생했습니다.

Pls 내 문제에 대한 완벽한 해결책을 제공합니다.

감사 U 녀석의 모든 .....

답변

0
다음과 같은 jQuery과 방법을 사용하는 것을 고려하고 싶을 수도있다

다음 indexPath 당신은 상단과 Parameters는 scrollPosition에 표시하려는 행을 포함

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath 
        animated:(BOOL)animated 
       scrollPosition:(UITableViewScrollPosition)scrollPosition 

을 UITableViewScrollPositionTop입니다.

테이블 뷰를 뒤로 스크롤하려면 다음 UITableView 메서드를 사용하여 보이는 화면의 맨 위에있는 행을 저장하십시오.

- (NSArray *)indexPathsForVisibleRows 

그런 다음 위에서 언급 한 첫 번째 방법으로 저장된 행으로 스크롤하십시오.