【发布时间】:2015-09-08 05:03:33
【问题描述】:
我使用主视图,屏幕底部有一个 TabBar。 每个选项卡项都应该指向一个特定的 CollectionView(带有特定的 API 调用)。
为了能够访问 UICollectionViewController,它必须首先被初始化。 所以我用了:
@main_controller = UITabBarController.alloc.init
layout = UICollectionViewFlowLayout.alloc.init
@main_controller.setViewControllers([
GeolocScreen.alloc.init,
ByNameController.alloc.initWithCollectionViewLayout(layout)
])
self.navigationController.pushViewController(@main_controller, animated:true)
话虽这么说:
如果不使用 PM::Screen 作为选项卡项,则选项卡图标和选项卡文本不会显示。这意味着,我必须单击图标才能在标签栏中显示图标/文本
然后我尝试调用 PM::Screen 而不是直接调用 UICollectionViewController,并将其作为子视图。 但我没能做到。
当我在我的 PM::Screen 中使用
layout = UICollectionViewFlowLayout.alloc.init
ctrl = ByNameController.alloc.initWithCollectionViewLayout(layout)
append!(ctrl, :ctrl_style).get
我明白了
终止应用到期 未捕获的异常 'NoMethodError',原因:'subviews.rb:229:in create_view:: undefined method (NoMethodError)
当我在我的 PM::Screen 中使用
layout = UICollectionViewFlowLayout.alloc.init
screen = ByNameController.alloc.initWithCollectionViewLayout(layout)
view = UIView.alloc.init
view.append(screen.view)
单击该图标没有任何作用。我从不输入 viewWillAppear,我猜这是合乎逻辑的,因为控制器只是被附加了......但是我的数据没有加载。
如果您有想法,我一定遗漏了一些明显的东西...谢谢!
PS:以防万一;我的控制器
class ByNameController < UICollectionViewController
attr_accessor :data
COLLECTION_CELL_ID = "ArtCell"
COLLECTION_HEADER_ID = "SectionHeader"
def viewDidLoad
super
self.title = App.name
rmq.stylesheet = CollectionStylesheet
collectionView.tap do |cv|
cv.registerClass(ArtCell, forCellWithReuseIdentifier: COLLECTION_CELL_ID)
cv.delegate = self
cv.dataSource = self
cv.allowsSelection = true
cv.allowsMultipleSelection = false
rmq(cv).apply_style :collection_view
end
reload_data
end
def reload_data
mp "RELAODING DATA "
Api.shared.url ".........json"
Api.shared.file_name "content.json"
Api.shared.download_data
end
def viewWillDisappear(animated)
App.notification_center.unobserve @reload_observer
end
def viewWillAppear(animated)
super
@reload_observer = App.notification_center.observe 'ReloadDataNotification' do |notification|
self.data = Api.shared.hash
self.collectionView.reloadData
end
end
def collectionView(view, numberOfItemsInSection: section)
self.data.nil? ? 0 : self.data["items"].reject{|i| i['name'] == "" }.count
end
def collectionView(view, cellForItemAtIndexPath: index_path)
view.dequeueReusableCellWithReuseIdentifier(COLLECTION_CELL_ID, forIndexPath: index_path).tap do |cell|
rmq.build(cell) unless cell.reused
art = {
art: self.data["items"][index_path.row]["art"],
name: self.data["items"][index_path.row]["name"],
thumb: self.data["items"][index_path.row]["thumb"]
}
cell.art = art
end
end
def collectionView(view, didSelectItemAtIndexPath: index_path)
selected = self.data["items"][index_path.row]
@store = StoreInfoController.alloc.init
@store.store_id = selected["storeID"]
self.navigationController.pushViewController(@store, animated:true)
end
end
【问题讨论】:
标签: ios rubymotion