有没有办法跳转到 Xcode 中的特定方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9794906/
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
Is there a way to jump to a specific method in Xcode?
提问by lancejjohnson
I'm using Xcode 4.3 for Objective-C development. One feature that I like in other text editors (I know Xcode is an IDE), is jumping to a method definition within the same code file.
我使用 Xcode 4.3 进行 Objective-C 开发。我在其他文本编辑器(我知道 Xcode 是一个 IDE)中喜欢的一个功能是跳转到同一代码文件中的方法定义。
For example if I'm in @implementation of Calculator and calculator has 10 methods, I will like a way to jump between them.
例如,如果我在 Calculator 的 @implementation 中并且计算器有 10 个方法,我会喜欢一种在它们之间跳转的方法。
If I press command+L I can jump to a specific line number, is there a way to jump in a similar way but to a method definition? e.g. instead of typing the line number to type only the beginning of the method name.
如果我按 command+LI 可以跳转到特定的行号,有没有办法以类似的方式跳转到方法定义?例如,不要键入行号,而只键入方法名称的开头。
Can I open somehow a dialog box, type the beginning of a method signature and see instantly the search results and If I pick one method it will get me to it?
我可以以某种方式打开一个对话框,输入方法签名的开头并立即查看搜索结果,如果我选择一种方法,它会让我找到它吗?
Is there a way to jump from a method to the next one?
有没有办法从一个方法跳转到下一个方法?
回答by lancejjohnson
I think this is what you're looking for:
我认为这就是你要找的:
Type ctrl-6to activate the "Show Document Items" in the "Jump Bar". Then start typing part of the method you are looking for to narrow the results.
键入ctrl-6以激活“跳转栏”中的“显示文档项目”。然后开始键入您要查找的方法的一部分以缩小结果范围。
Example:
例子:
To jump straight to - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
直接跳到 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Type ctrl-6, type "cellFor", arrow down so the method is highlighted, and press Enter. The Editor will jump right to that method.
键入ctrl- 6,键入“cellFor”,向下箭头以突出显示该方法,然后按Enter。编辑器将直接跳转到该方法。
Incidentally, you can use ctrl-1, ctrl-2, ctrl-3, etc. to access the different sections of the "Jump Bar".
顺便说一句,您可以使用ctrl- 1、ctrl- 2、ctrl-3等来访问“跳转栏”的不同部分。
回答by Archagon
If I understand you correctly, try Command-Shift-O. It also doubles as a file finder.
如果我理解正确,请尝试 Command-Shift-O。它还兼作文件查找器。
回答by Evan Anger
Perhaps I'm not understanding what you need, but it seems like you have a couple of options.
也许我不明白您需要什么,但您似乎有几个选择。
- Control+Command+Jshould take you to a definition.
- Control+Command+Up/Control+Command+Downwill toggle between .h/.m files.
- While in the .m file, I use the dropdown for the methods often.
- Control+ Command+J应该带你到一个定义。
- Control+ Command+ Up/ Control+ Command+Down将在 .h/.m 文件之间切换。
- 在 .m 文件中,我经常使用这些方法的下拉列表。
回答by Caleb
Select a symbol (could be a method, but doesn't have to be) and right-click (or control-click). The contextual menu that pops up has a "Jump to definition" command. Control-command-J is a shortcut for that.
选择一个符号(可能是一种方法,但不一定是)并右键单击(或按住 Control 单击)。弹出的上下文菜单有一个“跳转到定义”命令。Control-command-J 是一个快捷方式。
If the thing you're looking for isn't visible, you can use the Search Navigator (Command-3) to search through the code.
如果您要查找的内容不可见,您可以使用搜索导航器 (Command-3) 搜索代码。
Depending on what you're looking for, you may also find the Quick Help feature in the Utilities panel helpful. If you select a symbol, Quick Help will give you at least some basic information about that symbol. For symbols in the iOS or MacOS X API's, you get quite a bit of help. If you've selected your own symbol, it'll tell you where that symbol is declared, and you can click on the file name to jump to the declaration.
根据您要查找的内容,您可能还会发现“实用工具”面板中的“快速帮助”功能很有帮助。如果您选择一个符号,快速帮助将至少为您提供有关该符号的一些基本信息。对于 iOS 或 MacOS X API 中的符号,您会得到很多帮助。如果您选择了自己的符号,它会告诉您该符号的声明位置,您可以单击文件名跳转到声明。
I don't think there's a command to jump to the next method (where in the method would you want to jump to?). If you have a need for that sort of thing, you might find Xcode's code folding features useful. You can fold an entire method or just some of the blocks within the method. Very helpful for getting the lay of the land when you're looking at a large file for the first time.
我认为没有跳转到下一个方法的命令(您想跳转到方法中的哪个位置?)。如果您需要这种东西,您可能会发现 Xcode 的代码折叠功能很有用。您可以折叠整个方法或仅折叠方法中的一些块。当您第一次查看大文件时,这对于了解地形非常有帮助。
回答by William Cerniuk
If you want to press a command key sequence like Command+ Option+ ↓to jump to the next method, or Command+ Option+ ↑to jump to the previous method, there is no such animal in Xcode. Prior macOS development tools had such a capability, but Xcode is seriously lacking in the basics...
如果你想按这样的命令键序列Command+ Option+↓跳转到下一个方法,或Command+ Option+↑跳转到以前的方法,有在Xcode中没有这样的动物。之前的 macOS 开发工具有这样的能力,但 Xcode 严重缺乏基础......
The fastest jump back and forth in methods in a source file is to perform a Command+ F(Find) on [\-\+][ \t]*\(
as a regular expression. Then you can Command+ G(Find Next) to go to the next method or Command+ Shift+ G(Find Previous) to go to the prior method.
在源文件中的方法中最快的来回跳转是执行Command+ F(查找)[\-\+][ \t]*\(
作为正则表达式。然后您可以Command+ G(查找下一个)转到下一个方法或Command+ Shift+ G(查找上一个)转到上一个方法。
If you are disciplined in your method definitions, you might be able to search for - (
or + (
as a normal text string instead... a tad faster.
如果您对方法定义有纪律,那么您可能可以搜索- (
或+ (
作为普通文本字符串进行搜索……稍微快一点。
If this is a serious itch to scratch, maybe it is worth creating an Xcode plugin (as silly as this sounds for such a basic feature)... and post a link here for the rest of us ;-)
如果这是一个严重的问题,也许值得创建一个 Xcode 插件(对于这样一个基本功能来说听起来很愚蠢)......并在此处为我们其他人发布链接;-)