【问题标题】:Editable TextView with Second NavBar - Text appears, but too late带有第二个 NavBar 的可编辑 TextView - 出现文本,但为时已晚
【发布时间】:2009-05-25 14:11:46
【问题描述】:

带有第二个 NavBar 的可编辑 TextView - 出现文本,但为时已晚。

该应用有一个导航控制器。 我有一个基本上有三个级别的 iPhone 应用程序。

  1. 1 级 - 带有类别名称的表格

  2. 2 级 - 包含所选类别项目列表的表格

  3. Level 3 - 带有多个视图的选项卡式视图,包括用于项目详细信息的 UITextView 这些带有 TextView 的选项卡式视图之一是可编辑的。

    当用户在可编辑的 TextView 中点击键盘时 出现。用户可以在 TextView 中输入。出现字符 因为它们是键入的。

    在这个 Level 3 TextView 的顶部有一个 NavBar(存在于所有 3 个级别 更改),右侧有一个 BackButton 和一个“home->Level1”按钮。

一切正常,直到在可编辑的 TextView 中我添加了第二个 NavigationBar 在现有的导航栏下方。第二个 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];

}

【问题讨论】:

  • 第二个 NavBar 隐藏了 UITextEdit 的区域,因此我必须输入大约四行才能看到文本。我相信我需要将 UITextEdit 的高度降低 44 像素。

标签: iphone keyboard uitextview uinavigationbar


【解决方案1】:

第二个 NavBar 隐藏了 UITextEdit 的区域 这样我必须输入大约四行才能看到文本。我相信 我需要将 UITextEdit 的高度降低 44 像素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    相关资源
    最近更新 更多