0

2 番目の NavBar を備えた編集可能な TextView - テキストが表示されますが、遅すぎます。

アプリには 1 つのナビゲーション コントローラーがあります。基本的に 3 つのレベルを持つ iPhone アプリがあります。

  1. レベル 1 - カテゴリ名を含むテーブル

  2. レベル 2 - 選択したカテゴリのアイテムのリストを含むテーブル

  3. レベル 3 - アイテムの詳細を表示する UITextView を含む複数のビューを含むタブ付きビュー TextView を使用したこれらのタブ付きビューの 1 つが編集可能です。

    ユーザーが編集可能な TextView をタップすると、キーボードが表示されます。ユーザーは TextView に入力できます。文字は入力したとおりに表示されます。

    このレベル 3 TextView の上部には、右側に BackButton と「home->Level1」ボタンを備えた NavBar (変更のある 3 つのレベルすべてに存在) があります。

編集可能な TextView で、既存の NavBar の下に 2 つ目の NavigationBar を追加するまで、すべて正常に機能します。この 2 番目の NavBar にも 2 つのボタンがあります。それらは保存/キャンセルです。

これらの [保存] ボタンと [キャンセル] ボタンをクリックすると、正しいアクション メソッドに到達します。1 つの例外を除いて、すべてが完璧です。入力されたテキストは、[保存] または [キャンセル] ボタンがタッチされるまで 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];

}
4

1 に答える 1

0

2 番目の NavBar は UITextEdit の領域を隠していたため、テキストが表示されるまでに約 4 行入力する必要がありました。UITextEdit の高さを 44 ピクセル下げる必要があると思います。

于 2009-05-27T00:53:33.953 に答える