このコードのほとんどは、RubyMotionLocationsサンプルから直接派生しています。
単純な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のドキュメントをオンラインで調べましたが、そこに手がかりは見つかりませんでした。
私はメインプロパティを使用してそれを回避しました。誰かが私がこの振る舞いを見ている理由を理解するのを手伝ってくれることを願っています。