motion-table 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # MotionTable
2
2
 
3
- MotionTable is a RubyMotion gem for easily building table views in iOS.
3
+ MotionTable is a RubyMotion gem for easily building table views in iOS.
4
+
5
+ Feedback welcome: jamon@clearsightstudio.com(@jamonholmgren) or silas@clearsightstudio.com(@silasjmatson)
4
6
 
5
7
 
6
8
  ## Installation
@@ -33,22 +35,27 @@ class MyController < UITableViewController
33
35
  super
34
36
  self.title = "Settings"
35
37
 
36
- @grouped_table_view_data ||= [
37
- {
38
- title: "Your Account",
39
- cells: [
40
- { title: "Edit Profile", action: :edit_profile},
41
- { title: "Log Out", action: :log_out },
42
- ]
43
- },
44
- {
45
- title: "My App",
46
- cells: [
47
- { title: "About", action: :something_here },
48
- { title: "Feedback", action: :something_here }
49
- ]
50
- }
51
- ]
38
+ @grouped_table_view_data ||= [{
39
+ title: "Your Account",
40
+ cells: [
41
+ { title: "Edit Profile", action: :edit_profile},
42
+ { title: "Log Out", action: :log_out },
43
+ ]
44
+ }, {
45
+ title: "My App Settings",
46
+ cells: [{
47
+ title: "Be Awesome",
48
+ accessory: :switch,
49
+ accessoryDefault: true,
50
+ accessoryAction: :save_being_awesome
51
+ }, {
52
+ title: "Mute",
53
+ accessory: :switch,
54
+ accessoryDefault: false,
55
+ accessoryAction: :save_mute
56
+ },
57
+ ]
58
+ }]
52
59
 
53
60
  self.view = self.createTableViewFromData(@grouped_table_view_data)
54
61
  end
@@ -60,6 +67,18 @@ class MyController < UITableViewController
60
67
  def edit_profile
61
68
  # Implement your edit_profile view here
62
69
  end
70
+
71
+ def save_being_awesome(args)
72
+ # Depending on whether the switch is on or off,
73
+ # args => { value: true } or
74
+ # args => { value: false }
75
+ end
76
+
77
+ def save_mute(args)
78
+ # Depending on whether the switch is on or off,
79
+ # args => { value: true } or
80
+ # args => { value: false }
81
+ end
63
82
  end
64
83
  ```
65
84
 
@@ -68,6 +87,7 @@ end
68
87
  ```ruby
69
88
  class MyController < UITableViewController
70
89
  include MotionTable::PlainTable
90
+ inclued MotionTable::SearchableTable # For search capability
71
91
 
72
92
  def viewDidLoad
73
93
  super
@@ -88,6 +108,7 @@ class MyController < UITableViewController
88
108
  }
89
109
  ]
90
110
 
111
+ self.makeSearchable # Will add search capability if you include MotionTable::SearchableTable, nothing more needed :)
91
112
  self.view = self.createTableViewFromData(@plain_table_view_data)
92
113
  end
93
114
 
@@ -95,11 +116,11 @@ class MyController < UITableViewController
95
116
  # load this friend based on id
96
117
  end
97
118
 
98
- def something_here(args)
119
+ def something_here(args={})
99
120
  # You can pass any data structure into :arguments, it is just passed as an argument to your implementation
100
121
  # You have to handle it. Like so:
101
122
  args.each do |k, v|
102
- puts "Argument passed: #{v}""
123
+ puts "Argument passed: #{v}"
103
124
  end
104
125
  end
105
126
  end
@@ -1,6 +1,7 @@
1
1
  module MotionTable
2
2
  module PlainTable
3
3
  include MotionTable::SectionedTable
4
+ include MotionTable::SearchableTable
4
5
 
5
6
  def tableView
6
7
  @tableView ||= UITableView.alloc.initWithFrame(self.view.frame, style:UITableViewStylePlain)
@@ -0,0 +1,42 @@
1
+ module MotionTable
2
+ module SearchableTable
3
+ def makeSearchable
4
+ searchBar = UISearchBar.alloc.initWithFrame(CGRectMake(0, 0, 320, 44))
5
+ @contactsSearchDisplayController = UISearchDisplayController.alloc.initWithSearchBar(searchBar, contentsController: self)
6
+ @contactsSearchDisplayController.delegate = self
7
+ @contactsSearchDisplayController.searchResultsDataSource = self
8
+ @contactsSearchDisplayController.searchResultsDelegate = self
9
+
10
+ self.tableView.tableHeaderView = searchBar
11
+ end
12
+
13
+ def searchDisplayController(controller, shouldReloadTableForSearchString:searchString)
14
+ @mt_table_view_groups = []
15
+
16
+ @original_data.each do |section|
17
+ newSection = {}
18
+ newSection[:cells] = []
19
+
20
+ section[:cells].each do |cell|
21
+ if cell[:title].to_s.downcase.strip.include?(searchString.downcase.strip)
22
+ newSection[:cells] << cell
23
+ end
24
+ end
25
+
26
+ if newSection.count > 0
27
+ newSection[:title] = section[:title]
28
+ @mt_table_view_groups << newSection
29
+ end
30
+ end
31
+ true
32
+ end
33
+
34
+ def searchDisplayControllerWillEndSearch(controller)
35
+ @mt_table_view_groups = @original_data.clone
36
+ end
37
+
38
+ def searchDisplayControllerWillBeginSearch(controller)
39
+ @original_data = @mt_table_view_groups.clone
40
+ end
41
+ end
42
+ end
@@ -1,13 +1,22 @@
1
1
  module MotionTable
2
2
  module SectionedTable
3
- # Likely the only method you need call from the controller
3
+
4
4
  # @param [Array] Array of table data
5
5
  # @returns [UITableView] delegated to self
6
6
  def createTableViewFromData(data)
7
- @mt_table_view_groups = data
7
+ setTableViewData data
8
8
  return tableView
9
9
  end
10
10
 
11
+ def updateTableViewData(data)
12
+ setTableViewData data
13
+ @tableView.reloadData
14
+ end
15
+
16
+ def setTableViewData(data)
17
+ @mt_table_view_groups = data
18
+ end
19
+
11
20
  def numberOfSectionsInTableView(tableView)
12
21
  return @mt_table_view_groups.length if @mt_table_view_groups
13
22
  0
@@ -23,14 +32,24 @@ module MotionTable
23
32
  end
24
33
 
25
34
  def tableView(tableView, cellForRowAtIndexPath:indexPath)
35
+ dataCell = cellAtSectionAndIndex(indexPath.section, indexPath.row)
36
+
26
37
  cellIdentifier = "Cell"
27
38
 
28
- cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
29
- cell ||= UITableViewCell.alloc.initWithFrame(CGRectZero, reuseIdentifier:cellIdentifier)
30
-
31
- row = cellAtSectionAndIndex(indexPath.section, indexPath.row)
32
- cell.text = row[:title]
33
- return cell
39
+ tableCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
40
+ unless tableCell
41
+ tableCell = UITableViewCell.alloc.initWithFrame(CGRectZero, reuseIdentifier:cellIdentifier)
42
+ tableCell.accessoryView = dataCell[:accessoryView] if dataCell[:accessoryView]
43
+
44
+ if dataCell[:accessory] && dataCell[:accessory] == :switch
45
+ switchView = UISwitch.alloc.initWithFrame(CGRectZero)
46
+ switchView.addTarget(self, action: "accessoryToggledSwitch:", forControlEvents:UIControlEventValueChanged);
47
+ switchView.on = true if dataCell[:accessoryDefault]
48
+ tableCell.accessoryView = switchView
49
+ end
50
+ end
51
+ tableCell.text = dataCell[:title]
52
+ return tableCell
34
53
  end
35
54
 
36
55
  def sectionAtIndex(index)
@@ -44,18 +63,36 @@ module MotionTable
44
63
  def tableView(tableView, didSelectRowAtIndexPath:indexPath)
45
64
  cell = cellAtSectionAndIndex(indexPath.section, indexPath.row)
46
65
  tableView.deselectRowAtIndexPath(indexPath, animated: true);
47
- if self.respond_to?(cell[:action])
48
- expectedArguments = self.method(cell[:action]).arity
66
+ triggerAction(cell[:action], cell[:arguments]) if cell[:action]
67
+ end
68
+
69
+ def accessoryToggledSwitch(switch)
70
+ tableCell = switch.superview
71
+ indexPath = tableCell.superview.indexPathForCell(tableCell)
72
+
73
+ dataCell = cellAtSectionAndIndex(indexPath.section, indexPath.row)
74
+ dataCell[:arguments] = {} unless dataCell[:arguments]
75
+ dataCell[:arguments][:value] = switch.isOn
76
+
77
+ triggerAction(dataCell[:accessoryAction], dataCell[:arguments]) if dataCell[:accessoryAction]
78
+
79
+ end
80
+
81
+ def triggerAction(action, arguments)
82
+ $stderr.puts "Action: #{action.to_s} and args #{arguments.to_s}"
83
+ if self.respond_to?(action)
84
+ expectedArguments = self.method(action).arity
49
85
  if expectedArguments == 0
50
- self.send(cell[:action])
86
+ self.send(action)
51
87
  elsif expectedArguments == 1
52
- self.send(cell[:action], cell[:arguments])
88
+ self.send(action, arguments)
53
89
  else
54
- MotionTable::Console.log("MotionTable warning: #{cell[:action]} expects #{expectedArguments} arguments. Maximum number of required arguments for an action is 1.", withColor: MotionTable::Console::RED_COLOR)
90
+ MotionTable::Console.log("MotionTable warning: #{action} expects #{expectedArguments} arguments. Maximum number of required arguments for an action is 1.", withColor: MotionTable::Console::RED_COLOR)
55
91
  end
56
92
  else
57
- MotionTable::Console.log(self, actionNotImplemented: cell[:action])
93
+ MotionTable::Console.log(self, actionNotImplemented: action)
58
94
  end
59
95
  end
96
+
60
97
  end
61
98
  end
@@ -1,3 +1,3 @@
1
1
  module MotionTable
2
- VERSION = "0.1.5" unless defined?(MotionTable::VERSION)
2
+ VERSION = "0.1.6" unless defined?(MotionTable::VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-29 00:00:00.000000000 Z
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: MotionTable is a RubyMotion gem that makes it easy to handle UITableViews
15
15
  from a UITableViewController. Simply include in the module in your controller.
@@ -29,6 +29,7 @@ files:
29
29
  - lib/motion-table/console.rb
30
30
  - lib/motion-table/grouped_table.rb
31
31
  - lib/motion-table/plain_table.rb
32
+ - lib/motion-table/searchable_table.rb
32
33
  - lib/motion-table/sectioned_table.rb
33
34
  - lib/motion-table/version.rb
34
35
  - motion-table.gemspec