Xcode 4 中多参数方法名称的代码完成
在 Xcode4 中,我发现我无法让代码完成轻松缩小第一部分常见的多参数方法名称的范围。例如,考虑 UITableViewDelegate
中的以下方法
- tableView:viewForHeaderInSection:
- tableView:heightForHeaderInSection:
- tableView:accessoryTypeForRowWithIndexPath:
...
:这样的例子不胜枚举;有很多方法可以启动tableView
。如果我输入“tableView”,列表会很长并且无法快速导航。如果我输入“tableView:”,则一旦输入冒号 (:),代码完成就会退出。如果我输入诸如“tableViewview”之类的连续内容,完成也会退出,大概是因为它不再与第一个方法名称部分字面匹配。
有没有某种方法可以通过键盘完成这样的列表,而不需要通过鼠标四处移动或敲击随机数量的箭头键来导航长列表?我很难相信多参数 Objective-C 方法的代码完成是如此有限,但到目前为止,实验和文档都没有被证明具有启发性。
更新澄清: 上面我指的是方法声明的完成(例如在 .m 文件中),而不是方法调用的完成。对于方法调用,Xcode 4.x 独立完成每个方法参数部分;这很好用。上述问题仅适用于声明,通常是在 .m 文件中开始编写新方法实现时。
In Xcode4, I'm finding that I can't get code completion to readily narrow for multi-parameter method names where the first part is common. For example, consider the following methods from UITableViewDelegate
:
- tableView:viewForHeaderInSection:
- tableView:heightForHeaderInSection:
- tableView:accessoryTypeForRowWithIndexPath:
...
The list goes on; there are quite a few methods that start tableView
. If I type "tableView", the list is long and not quickly navigated. If I type "tableView:", code completion is exited as soon as I type the colon (:). If I type a run-on such as "tableViewview", completion also exits, presumably as it no longer literally matches the first method name part.
Is there some way to complete via the keyboard on such a list without resorting to either mousing around or clattering out a random number of arrow key hits to navigate the long list? I'm having a hard time believing that code completion for multi-parameter Objective-C methods is so limited, but neither experimentation nor documentation have proved illuminating thus far.
Update for clarification:
Above I'm referring to completion of a method declaration (e.g. in a .m file), not of a method call. For method calls, Xcode 4.x does completion for each method parameter part independently; this works great. The problem above only applys to declarations, generally when starting to write a new method implementation in a .m file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,Xcode 中似乎没有实现您期望的行为。但是,我找到了部分解决方案:当您指定多参数方法的完整第一部分时,代码完成有效,即如果您键入此内容(末尾带有空格)
并按 ESCAPE 键,则将出现代码完成对话框您将能够继续键入方法名称的其余部分。
您可能想知道:
代码片段来救援!您只需输入一次序言,然后 将其转换为片段。我发现最好按以下方式配置它,不要忘记在代码部分末尾添加空格,它会做事 你
应该如何使用你刚刚创建的东西? 在你的 .m 文件中开始输入
tabl 。
并且 Xcode 会让您自动完成代码片段,然后按 ESC 键显示自动完成列表。此解决方案不是很可靠,因为您必须为每个多部分方法创建一个代码片段。你想使用,但是它确实节省了一些时间,并且没有那么多共享相同前缀的多部分方法名称。
It does seems that the behavior you expect is (unfortunately) not implemented in Xcode. However, I've found a partial solution: code completion works when you specify the complete first part of the multi-parameter method, i.e. if you type this (with space at the end)
and press ESCAPE key then the code completion dialog will appear and you will be able to keep typing the rest of the method name.
You are probably wondering:
Code snippets to the rescue! You just have to type the preamble once and convert it into snippet. I found it's best to configure it the following way, don't forget to add space at the end of code part, it will make things easier.
How should you use the thing you've just created? In your .m file start typing
tabl
and Xcode will let you autocomplete the snippet for you. Once the preamble is placed press ESC to reveal the auto-completion list.This solution is not very robust, since you have to create a snippet for every multi-part method you want to use, but it does save some time and there aren't that many multi-part method names that share the same prefix.
我为这个问题苦恼了很长一段时间。现在我可以验证即使在最新的 Xcode 5 中也没有办法做到这一点,我提交了一份错误报告:
Xcode 中的多参数方法声明完成
如果您也需要,请复制它。
I'm annoyed by this problem for quite a long time. Now I can verify that there is no way to do even in the newest Xcode 5, I submitted a bug report:
Multi-parameter method declaration completion in Xcode
Please dup it if you also want it.
哦,抱歉,它不能按照我在更新中提到的协议存根的方式工作。
为此,我使用了 Accessorizer,这是 mac 应用商店中的一个应用程序,用于完全实现您想要实现的委托/协议方法的声明。希望能有所帮助。
旧帖子:
我使用 Tab ⇥ 来实现此目的。
我经常举的例子:
您需要代码补全中的众多 init 方法之一。
那么您就不想向下滚动或使用多次击键来找到正确的方法。
点击i>点击 Tab ⇥ >
init
完成。点击 Escape ⎋,然后点击 w,然后再次点击 Tab ⇥ 以获取所有这些
initWith
方法。您甚至可以在第一个参数后使用 Tab ⇥ / Escape ⎋,当有多个只有一个参数的方法。
在您的情况下,请点击 t > >选项卡⇥>转义⎋> a 并返回 ↩,这就是第三种方法。
您还可以使用 Shift ⇧ + Tab ⇥ 跳转到上一个代码完成参数。
Oh sorry, it does not work that way I mentioned with protocol stubs like you wanted in your update.
I use Accessorizer for that, an app in the mac app store to fully implement the declaration of your delegate/protocol methods you want to implement. Hope that help a little bit.
Old post:
I use Tab ⇥ for this.
Example I often have:
You want one of many init methods in the code completion.
Then you don't want to scroll down or use to many keystrokes to get to the right method.
Hit i > hit Tab ⇥ >
init
is completed.Hit Escape ⎋ and then w and then again Tab ⇥ for all these
initWith
methods.You can even use Tab ⇥ / Escape ⎋ after the first parameter, when there is more than the method with only one parameter.
In your case hit t > Tab ⇥ > Escape ⎋ > a and Return ↩, there you got your third method.
You can also jump to the previous code completion argument with Shift ⇧ + Tab ⇥.