2009-05-25 41 views
0

帶有第二個導航欄的可編輯TextView - 出現文本,但太晚。帶有第二個導航欄的可編輯TextView - 出現文本,但太遲

該應用程序有一個單一的導航控制器。 我有一個基本上有三個級別的iPhone應用程序。

  1. 等級1 - 表類別名稱

  2. 等級2 - 表與所選類別的產品清單

  3. 3級 - 選項卡式瀏覽與一些意見,包括UITextView的對項目的詳細信息 帶有TextView的這些選項卡式視圖是可編輯的。

    當用戶點擊可編輯的TextView時,鍵盤 出現。用戶可以輸入TextView。字符在鍵入時出現 。

    在這個3級TextView的頂部有一個NavBar(帶有 變化的所有3個級別),帶有BackButton和右側的「home-> Level1」按鈕。

直到編輯的TextView我添加第二個導航欄 現有的NavBar下面的所有工作得很好。這第二個NavBar也有兩個按鈕 。他們是保存/取消。

當我點擊這些保存並取消按鈕時,正確的行動 方法已達到。除了一個例外,所有的都是完美的,文本 鍵入的內容不會出現在TextView中,直到 保存或取消按鈕被觸摸。下面是我的TabViewController.m中的相關按鈕設置和 操作方法。我需要堅持這個 數據。

我認爲從TextView獲取通知和操作handleTextChange會做的伎倆,但沒有運氣。我被卡住了。

......... 
- (void)loadView { 

    self.myTextView = [[UITextView alloc] init]; 
    self.myTextView.delegate = self; 

    self.view = self.myTextView; 
    //UITextViewTextDidChangeNotification 
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
    [nc addObserver:self 
    selector:@selector(handleTextChange:) 
    name:UITextViewTextDidChangeNotification 
    object:nil]; 
    NSLog(@"Registered DG_HandleChangeTextNotification with notification center."); 

} 

- (void)handleTextChange:(NSNotification *)note 
{ 
    [self.myTextView setNeedsDisplay] ; 
    NSLog(@"...Handled Text Change."); 
} 


- (void)textViewDidBeginEditing:(UITextView *)textView 
{ 
    // provide my own Done/Save button to dismiss the keyboard 

    saveNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
    saveNavigationBar.barStyle = UIBarStyleBlackOpaque; 
    UINavigationItem *doneItem = [[UINavigationItem alloc] init]; 
    doneItem.title = @"My Notes"; 

    UIBarButtonItem *doneItemButton = [[UIBarButtonItem alloc] 
     initWithBarButtonSystemItem:UIBarButtonSystemItemSave 
     target:self action:@selector(saveAction:)]; 
    UIBarButtonItem *cancelItemButton = [[UIBarButtonItem alloc] 
     initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self 
     action:@selector(cancelAction:)]; 

    [doneItem setRightBarButtonItem:doneItemButton animated:NO]; 
    [doneItem setLeftBarButtonItem:cancelItemButton animated:NO]; 
    [saveNavigationBar pushNavigationItem:doneItem animated:NO]; 

    [self.view addSubview:saveNavigationBar]; 

    [doneItem release]; 
    [cancelItemButton release]; 
    [doneItemButton release]; 
} 

- (void)saveAction:(id)sender 
{ 
    // finish typing text/dismiss the keyboard by removing it as the first responder 

     self.text = self.myTextView.text; 
    [self.saveNavigationBar removeFromSuperview]; 

    [self.myTextView resignFirstResponder]; 

} 

- (void)cancelAction:(id)sender 
{ 
    [self.saveNavigationBar removeFromSuperview]; 

    [self.myTextView resignFirstResponder]; 

} 
+0

第二個NavBar隱藏了UITextEdit 的區域,因此在我看到文本之前我必須輸入約四行。我相信我需要將UITextEdit的高度降低44個像素。 – mbarron 2009-05-27 00:50:56

回答

0

第二的NavBar藏身的UITextEdit 這樣的,我收到我看到的文字輸入約四線的區域。我相信 我需要將UITextEdit的高度降低44個像素。