Class: ScreenController
- Inherits:
-
UIViewController
- Object
- UIViewController
- ScreenController
show all
- Includes:
- AppConstants
- Defined in:
- app/controllers/screen_controller.rb
Constant Summary
AppConstants::ITEMS_PER_ROW, AppConstants::NUMBER_OF_SECTIONS, AppConstants::ROW_HEIGHT, AppConstants::STATUS_BAR_HEIGHT, AppConstants::VERTICAL_ROW_OFFSET
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
4
5
6
|
# File 'app/controllers/screen_controller.rb', line 4
def items
@items
end
|
Instance Method Details
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/screen_controller.rb', line 26
def create_new_horizontal_scroll_cell row_number
horizontal_row = HorizontalTableContainerCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier: self.class.name)
horizontal_row.delegate = self
horizontal_row.vertical_row_offset = VERTICAL_ROW_OFFSET
cell = horizontal_row.set_dimensions_with_row_offset
cell.items_list = row_number
cell.selectionStyle = UITableViewCellSelectionStyleNone
cell
end
|
36
37
38
39
40
|
# File 'app/controllers/screen_controller.rb', line 36
def row_number
start_index = ITEMS_PER_ROW * row_number
end_index = start_index + ITEMS_PER_ROW - 1
self.items[start_index..end_index]
end
|
#fetch_data ⇒ Object
68
69
70
71
72
73
|
# File 'app/controllers/screen_controller.rb', line 68
def fetch_data
generate_sample_models "city"
generate_sample_models "transport"
generate_sample_models "cats"
@table_view.reloadData
end
|
#generate_sample_models(category) ⇒ Object
75
76
77
78
79
80
81
82
|
# File 'app/controllers/screen_controller.rb', line 75
def generate_sample_models category
5.times do |n|
model = Model.new
model.name = "#{category} #{n}"
model.image_url = "http://lorempixel.com/130/207/#{category}/#{n}"
self.items << model
end
end
|
#get_row_count ⇒ Object
59
60
61
62
|
# File 'app/controllers/screen_controller.rb', line 59
def get_row_count
return 1 if self.items.nil?
(self.items.count.to_f/5).ceil
end
|
42
43
44
|
# File 'app/controllers/screen_controller.rb', line 42
def horizontal_scroll_cell_selected(item, index)
App.alert "#{item.name} at index #{index}"
end
|
#numberOfSectionsInTableView(table_view) ⇒ Object
64
65
66
|
# File 'app/controllers/screen_controller.rb', line 64
def numberOfSectionsInTableView(table_view)
NUMBER_OF_SECTIONS
end
|
46
47
48
49
|
# File 'app/controllers/screen_controller.rb', line 46
def set_item_details_for_horizontal_scroll_cell cell, item
cell.set_title_label_text item.name
cell.set_thumbnail_image_with_url item.image_url, "img.jpeg"
end
|
#tableView(table_view, numberOfRowsInSection: section) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'app/controllers/screen_controller.rb', line 17
def tableView(table_view, cellForRowAtIndexPath: index_path)
cell = table_view.dequeueReusableCellWithIdentifier(self.class.name)
unless cell
cell = create_new_horizontal_scroll_cell index_path.row
end
cell.reload_content
cell
end
|
#viewDidLoad ⇒ Object
6
7
8
9
10
11
12
13
14
15
|
# File 'app/controllers/screen_controller.rb', line 6
def viewDidLoad
super
self.items = []
self.view.backgroundColor = UIColor.whiteColor
@table_view = UITableView.alloc.initWithFrame([[0, STATUS_BAR_HEIGHT],[Device.screen.width, Device.screen.height - STATUS_BAR_HEIGHT]], style: UITableViewStylePlain)
@table_view.delegate = self
@table_view.dataSource = self
self.view.addSubview(@table_view)
fetch_data
end
|