このコードのほとんどは、RubyMotion Locationsサンプルから直接派生しています。コントローラのNSManagedObject NSStringにアクセスするときにNoMethodErrorを取得する
私はシンプルNSManagedObjectを定義した:
class Text < NSManagedObject
def self.entity
@entity ||= begin
# Create the entity for our Text class. The entity has 2 properties.
# CoreData will appropriately define accessor methods for the properties.
entity = NSEntityDescription.alloc.init
entity.name = 'Text'
entity.managedObjectClassName = 'Text'
entity.properties = ['main', NSStringAttributeType,'display',NSStringAttributeType].each_slice(2).map do |name, type|
property = NSAttributeDescription.alloc.init
property.name = name
property.attributeType = type
property.optional = false
property
end
entity
end
end
end
私は私のコントローラ内の表示方法にアクセスするように見えることはできません。
def tableView(tableView, cellForRowAtIndexPath:indexPath)
cell = tableView.dequeueReusableCellWithIdentifier(CellID) || UITableViewCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier:CellID)
text = TextStore.shared.texts[indexPath.row]
cell.textLabel.text = text.display
cell.detailTextLabel.text = text.main[0,10] + "...."
cell
end
私はこの例外を得続ける:
Terminating app due to uncaught exception 'NoMethodError', reason: 'text_controller.rb:40:in `tableView:cellForRowAtIndexPath:': private method `display' called for #<Text_Text_:0x8d787a0> (NoMethodError)
私はTextクラスとTextStoreクラス(モデル)にさまざまな変更を加えようとしました。これまでのところ、この問題は解決されていません。私はオンラインのAppleの文書でいくつかの調査を行ったが、そこに手がかりは見つかっていない。
私は、mainプロパティを使用してその問題を回避しました。なぜ誰かがこの行動を見ているのか理解できるように助けてくれることを願っています。
displayは、特定のポートにオブジェクトを印刷するためのKernel ...で定義されたメソッドです。RubyMotionでこの動作を回避するために非公開にされている可能性があります –
私はそれがこのようなものかもしれないと思ったが、 NSManagedObjectのドキュメントを参照してください。それはカーネル上にあることが分かります。ありがとうPaul.s – codewise