如何在Storyboard设计中创建accessoryInputView? [英] How can you create an accessoryInputView in a Storyboard design?

查看:148
本文介绍了如何在Storyboard设计中创建accessoryInputView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个accessoryInputView来使用一些特定于应用程序的键来增强键盘。

I am trying to create an accessoryInputView to augment the keyboard with some app-specific keys.

我使用基于Storyboard的设计方法来保持UI与应用程序逻辑分离。

I am using a Storyboard based design approach to keep the the UI separated from the application logic.

我似乎无法理解如何创建新视图并将其与textView相关联。有可能吗?

I cannot seem to understand how to create the new view and associated it with the textView. Is it possible?

推荐答案

如果有其他人试图这样做,让我记录下我最后做的事情。

In case anyone else is trying to do this, let me record what I ended up doing.

我用它想要的accessoryView创建了一个新的XIB。我无法弄清楚如何将inputBccessoryView的
直接分配到故事板设计中,所以我做了以下内容。

I created a new XIB with the accessoryView I wanted in it. I could not figure out how to assign the inputAccessoryView directly into a storyboard design, so I did the following.

我将XIB的fileOwner作为包含需要accessoryView的textView并将视图分配给该类中的IBOutlet的控制器类。这允许我加载XIB并自动将其分配给IBOutlet。

I made the fileOwner of the XIB as the controller class that contains the textView that needs the accessoryView and assigned the view to a IBOutlet in that class. That allows me to load the XIB and auto-assign it to the IBOutlet.

然后在viewDidLoad中,我将IBOutlet分配给需要它的textView。它运行良好,允许我在IB中完成所有UI工作并将逻辑保留在控制器中。我想我可以考虑将inputAccessoryView设置为'logic'而不是UI设计,并认为这是一个很好的设计。不是很好,因为IB不允许直接从XIB设置inputAccessoryView或在故事板中创建不属于应用程序流的视图。

Then in the viewDidLoad, I assign the IBOutlet to the textView that needs it. It works well and allows me to do all the UI work in IB and keep the logic in the controller. I guess I can consider setting the inputAccessoryView as 'logic' and not UI design and consider this a good design. Not stellar, since IB does not allow setting the inputAccessoryView directly from a XIB or creating views in a storyboard that are not part of the flow of the app.

viewDidLoad看起来像:

The code in viewDidLoad looks like:

- (void) viewDidLoad
{
    ...   
    [super viewDidLoad];
    [[NSBundle mainBundle] loadNibNamed:@"NoteInputAccessoryView" owner:self options:nil];

    _noteTextView.inputAccessoryView=_noteInputAccessoryView;
    ...
}

这篇关于如何在Storyboard设计中创建accessoryInputView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆