Xcode最强大的功能之一就是它的Intellisense完成功能,它会在您输入Foundation/Cocoa/UIKit API的名称时显示潜在候选项列表.我对MacRuby,PyObjC或更新的RubyMotion非常感兴趣,但是如果没有代码完成,这些工具似乎比它们的价值更麻烦.
上述三种技术中的任何一种,对于任何文本编辑器(但最好是Vim或Xcode),是否有任何代码完成功能(不一定是Intellisense )?IDE解决方案的奖励点,允许在单个命令中构建和运行应用程序(如Xcode的"运行"按钮).
据我所知,Xcode 4放弃了对MacRuby/PyObjC的支持,因此Intellisense不再可用.为了完成代码,我应该在Xcode 4旁边安装Xcode 3吗?其他人如何做到这一点(当然你们使用某种形式的代码完成 - 我不相信任何人都能记住Foundation/Cocoa/UIKit中的所有类)?
我是 OSX 开发的初学者,所以我希望我的问题能在这里找到解决方案。
我的NSTokenField应用程序中有一个,我实现了该tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:方法。
一切正常,但目前的结果是这样的:

我想要的是让它看起来像这样:(类似于邮件应用程序中的完成)

这意味着我希望完成列表采用所有 NSTokenField 宽度。使用Accessibility Inspector,我可以看到与第一个 sreenshot 对应的层次结构是:
AXScrollArea -> AXList -> AXTextField
而对应于第二个屏幕截图的是:
AXScrollArea -> AXTable -> AXRow:AXTableRow -> AXTextField
所以我想我必须使用 anNSTableView来显示完成列表,但我不知道如何实现。有谁知道这怎么可能?
在此先感谢您的帮助。
编辑
至少有 2 人建议我实现该tokenField:menuForRepresentedObject:方法并使用适当的NSMenu属性定义菜单宽度。但是这个方法用于为给定的令牌定义一个菜单,我已经实现了它:
def tokenField(tokenField, menuForRepresentedObject:representedObject)
theMenu = NSMenu.alloc.initWithTitle("Email address context menu")
item_0 = theMenu.insertItemWithTitle('add_to_address_book'.localized, action:'add_to_address_book', keyEquivalent:"", atIndex:0)
item_0.setTarget(self)
item_1 = theMenu.insertItemWithTitle('new_message'.localized, action:'new_message', keyEquivalent:"", atIndex:1)
item_1.setTarget(self)
theMenu
end
Run Code Online (Sandbox Code Playgroud)
这给了我这样的东西:

很棒的东西,但不是我在这里问的。
什么是OS X相当于ios'(Ruby风格):
@window.rootViewController = NSViewController.alloc.initWithNibName(nil, bundle: nil)
Run Code Online (Sandbox Code Playgroud)
有两个方面:
我正在尝试用代码构建一个窗口(没有nib)......并按照Pragmatic的RubyMotion程序员指南(为iOS编写).
有没有人在使用joybox更新rubymotion时遇到问题?我刚刚更新了rubymotion今天早上我的应用程序立即崩溃...这是我的错误.
Inheriting from Motion::Project::Command' has been deprecated, inherit fromMotion::Command' instead.
Run Code Online (Sandbox Code Playgroud)
不知道这是不是为什么它会破裂......但我需要弄明白这一点.我试过回滚版本,找不到适用的版本.非常感激任何的帮助.
我尝试将时间的文本表示解析为ruby Time对象.
通常在ruby中,我会这样做:
require 'time'
Time.parse('2010-12-15T13:16:45Z')
# => 2010-12-15 13:16:45 UTC
Run Code Online (Sandbox Code Playgroud)
在RubyMotion中,我无法使用libs,并且Time.parse不可用:
(main)> require 'time'
=> #<RuntimeError: #require is not supported in RubyMotion>
(main)>
(main)> Time.parse
=> #<NoMethodError: undefined method `parse' for Time:Class>
Run Code Online (Sandbox Code Playgroud)
有没有办法要求ruby提供的时间库,而不必复制和重写整个代码,使其与RubyMotion兼容?
有没有办法通过addTarget调用传递参数,因为它调用另一个函数?
我也试过了发送方法 - 但这似乎也破了.在不创建全局变量的情况下传递参数的正确方法是什么?
@my_button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
@my_button.frame = [[110,180],[100,37]]
@my_button.setTitle("Press Me", forState:UIControlStateNormal)
@my_button.setTitle("Impressive!", forState:UIControlStateHighlighted)
# events
newtext = "hello world"
@my_button.addTarget(self, action:'buttonIsPressed(newtext)', forControlEvents:UIControlEventTouchDown)
view.addSubview(@my_button)
def buttonIsPressed (passText)
message = "Button was pressed down - " + passText.to_s
NSLog(message)
end
Run Code Online (Sandbox Code Playgroud)
更新:
好的,这是一个有效的实例变量的方法.
@my_button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
@my_button.frame = [[110,180],[100,37]]
@my_button.setTitle("Press Me", forState:UIControlStateNormal)
@my_button.setTitle("Impressive!", forState:UIControlStateHighlighted)
# events
@newtext = "hello world"
@my_button.addTarget(self, action:'buttonIsPressed', forControlEvents:UIControlEventTouchDown)
view.addSubview(@my_button)
def buttonIsPressed
message = "Button was pressed down - " + @newtext
NSLog(message)
end
Run Code Online (Sandbox Code Playgroud) 我需要获取当前NSDate.date时间并删除时区并将其解析为GMT日期
NSDate.date
Run Code Online (Sandbox Code Playgroud)
回报 2012-10-11 11:27:09 -0700
我需要的是这个: 2012-10-11 11:27:09 +0000
我正在尝试在RubyMotion应用程序中自定义导航栏,但似乎无法更改标题文本字体或颜色.我可以设置背景图像和色调,但不能设置标题属性.
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
navigationBar = UINavigationBar.appearance
#navigationBar.setBackgroundImage(UIImage.imageNamed('navigation-bar-background.png'), forBarMetrics: UIBarMetricsDefault)
#navigationBar.setTintColor(UIColor.greenColor)
navigationBar.setTitleTextAttributes({
UITextAttributeFont: UIFont.fontWithName('Trebuchet MS', size:24),
UITextAttributeTextShadowColor: UIColor.colorWithWhite(0.0, alpha:0.4),
UITextAttributeTextColor: UIColor.blueColor
})
puts navigationBar.titleTextAttributes.inspect
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(MainMenuController.alloc.init)
@window.rootViewController.wantsFullScreenLayout = true
@window.makeKeyAndVisible
true
end
end
Run Code Online (Sandbox Code Playgroud)
控制台输出显示了以下对于inspect语句:
{:UITextAttributeFont=>#<UICFFont:0x963aa70>,
:UITextAttributeTextShadowColor=>UIColor.color(0x0, 0.0),
:UITextAttributeTextColor=>UIColor.blueColor}
Run Code Online (Sandbox Code Playgroud)
所以看起来一切都设置正确,但我得到的只是带有白色文字的标准蓝色导航栏.
我刚刚开始使用RubyMotion,据我所知,它建议将NSUserDefaults用于数据存储.这似乎有点奇怪,因为名称表明它应该只用于存储配置变量等而不是对象.
可以在NSUserDefaults中存储我的对象(例如用户,公司,任务等),还是应该使用其他方法?
我想在RubyMotion中定义全局常量.声明全局常量的最佳方法是什么?
如果它是Rails config/initializers/constants.rb,我认为将全局常量放入常见的方式.RubyMotion中的任何替代位置?
rubymotion ×10
ios ×3
objective-c ×3
cocoa ×2
macruby ×2
ruby ×2
cocoa-touch ×1
ios5 ×1
macos ×1
nsdate ×1
pyobjc ×1
rubygems ×1
xcode ×1