TitaniumでTableViewにTableViewRowが追加できなくて死にたくなったメモ
RTFMだった件。
@articles.fetch(
success: =>
for article in @articles
c = Alloy.createController('row')
c.articleTitle.text = article.title
$.articleSection.add c.getView()
Ti.App.fireEvent('onloadView')
)
とかやってたんです。
Titanium AlloyのSync Adapterでナイススケルトン2で作ったスケルトンで調子こいてたときは問題なかったんですが、最終的に画面ができたときにRESTfulなアダプタに切り替えてやったらTableViewの中身が何にもでない。
さんざ、迷った挙句、いきついた先は公式ドキュメント。最初から見ろよな。
http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.TableViewSection
Before the table is rendered, the TableViewSection add method may be used to add TableViewRow objects to a section. After it is rendered, one of the TableView insertRowBefore, insertRowAfter, or appendRow methods must be used instead.
このとおり、tableがレンダリングされるまええはTableViewSectionのaddでいいけど、レンダリング後はTableViewのinsertRowBefore, insertRowAfter, appendRowのどれかじゃないとダメよ。と書いてあった。
というわけで、以下のように書きなおしたらうまくいった。
@articles = Alloy.createCollection('article') @articles.fetch( success: => for article in @articles c.articleTitle.text = article.title $.articleList.appendRow c.getView() Ti.App.fireEvent('onloadView') )
sampleアダプタのときは、Tableがレンダリングされるより早く処理が済んでたのね。
信用しろよ・・・ドキュメントを・・・っ!
![銀と金 全11巻完結 [マーケットプレイス コミックセット] [−] by 銀と金 全11巻完結 [マーケットプレイス コミックセット] [−] by](http://ecx.images-amazon.com/images/I/51UEDfq7bQL._SL160_.jpg)
銀と金 全11巻完結 [マーケットプレイス コミックセット] [−] by
- メディア: コミック
- クリック: 1回
- この商品を含むブログ (1件) を見る