Xcode 方法导航

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5359039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:34:09  来源:igfitidea点击:

Xcode method navigation

xcode

提问by Bill

In Xcode 4, I can press Ctrl-6 to get a list of all the methods in the current file.

在 Xcode 4 中,我可以按 Ctrl-6 来获取当前文件中所有方法的列表。

The problem is, if I have private methods declared at the top of my implementation file, say:

问题是,如果我在实现文件的顶部声明了私有方法,请说:

@interface Foo ()

-(void)tap:(id)sender;

@end

@implementation Foo

...

-(void)tap:(id)sender
{
  ...
}

then starting to type "tap" while the method list is visible will just take me to the declaration, since it comes first in the file, when what I really want is the implementation.

然后在方法列表可见时开始键入“tap”只会带我进入声明,因为它首先出现在文件中,而我真正想要的是实现。

Is there any way to exclude these declarations from the method list or do I need to resort to separate Foo.hand Foo+Private.hheaders?

有什么方法可以从方法列表中排除这些声明,还是需要使用单独的Foo.hFoo+Private.h标题?

Thanks!

谢谢!

采纳答案by Caleb

I don't think there's a way to exclude the method declarations from the Document Items popup.

我认为没有办法从 Document Items 弹出窗口中排除方法声明。

If you get in the habit of using code folding, however, you might not rely so much on that popup to navigate your source code. There are commands for folding both methods and comment blocks, and you can fold all methods with one quick shortcut (command-option-shift-left arrow to fold, -right arrow to unfold by default, though you can of course customize the keys). See the Editor->Code Folding submenu for a complete list of related commands.

但是,如果您养成了使用代码折叠的习惯,那么您可能不太依赖该弹出窗口来导航您的源代码。有折叠方法和注释块的命令,您可以使用一个快捷方式折叠所有方法(命令-选项-shift-左箭头折叠,-右箭头默认展开,当然您可以自定义键) . 有关相关命令的完整列表,请参阅 Editor->Code Folding 子菜单。

When you fold all comments and methods in a .m file, almost all you're left with is a list of methods that's makes it easy to find what you're looking for. You can then unfold just that method or all methods with another keystroke. It's a little strange to see all your code disappear when you first start using folding, but it's a very handy feature.

当您将所有注释和方法折叠在一个 .m 文件中时,您几乎只剩下一个方法列表,可以轻松找到您要查找的内容。然后,您可以通过另一次击键仅展开该方法或所有方法。当您第一次开始使用折叠时,看到所有代码都消失了,这有点奇怪,但这是一个非常方便的功能。

回答by Robert

You dont need to declare you private methods and you wont get a warning by default anymore. So one options is not to declare a prototype at all.

你不需要声明你的私有方法,默认情况下你不会再收到警告。因此,一种选择是根本不声明原型。

Otherwise as curthipster mentioned ctrl-6 is a good shortcut. I use this all the time (no mouse needed):

否则正如 curthipster 提到的 ctrl-6 是一个很好的捷径。我一直使用这个(不需要鼠标):

  1. Press ctrl-6
  2. Type the first few letter of the method name (or a word it contains and you dont even have to spell it spot on, the search filter is very good!)
  3. Tap down until the method is selected.
  4. Tap enter
  1. 按 ctrl-6
  2. 输入方法名称的前几个字母(或者它包含的一个词,你甚至不必拼写,搜索过滤器非常好!)
  3. 点击直到选择方法。
  4. 点击进入

Alternativly open the assistant with cmd-alt enter (to close use cmd-enter, see more shortcuts here). You can make the assistant editor look at the same file, so it has one part of view at the top and one at the bottom for example.

或者使用 cmd-alt enter 打开助手(要关闭使用 cmd-enter,请在此处查看更多快捷方式)。您可以让助理编辑器查看同一个文件,例如,它有一部分视图在顶部,另一部分在底部。

回答by Macmade

Usually, it's better to add a named category for the private methods:

通常,最好为私有方法添加一个命名类别:

#import "Foo.h"

@interface Foo( Private )
    - ( void )tap: ( id )sender;
@end

@implementation Foo( Private )
    - ( void )tap: ( id )sender
    {}
@end

@implementation Foo
    ...
@end

Then you'll see each one. It may not answer your question, but at least you'll see your method.

然后你会看到每一个。它可能无法回答您的问题,但至少您会看到您的方法。

One thing is also to organize your methods with markpragmas:

还有一件事是用mark编译指示来组织你的方法:

#pragma mark - Private methods

May help you to navigate through the completion dialog... Hope this helps...

可以帮助您浏览完成对话框...希望这会有所帮助...