Class: Nitron::TableViewController::CoreDataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/nitron/table_view_controller.rb

Instance Method Summary collapse

Instance Method Details

#initWithRequest(request, owner: owner, sectionNameKeyPath: sectionNameKeyPath, options: options) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/nitron/table_view_controller.rb', line 112

def initWithRequest(request, owner:owner, sectionNameKeyPath:sectionNameKeyPath, options:options)
  if init
    context = UIApplication.sharedApplication.delegate.managedObjectContext

    @className = owner.class.name
    @controller = NSFetchedResultsController.alloc.initWithFetchRequest(request,
                                                                        managedObjectContext:context,
                                                                        sectionNameKeyPath:sectionNameKeyPath,
                                                                        cacheName:nil)
    @controller.delegate = owner
    @options = options

    errorPtr = Pointer.new(:object)
    unless @controller.performFetch(errorPtr)
      raise "Error fetching data"
    end
  end

  self
end

#numberOfSectionsInTableView(tableView) ⇒ Object



133
134
135
# File 'lib/nitron/table_view_controller.rb', line 133

def numberOfSectionsInTableView(tableView)
  @controller.sections.size
end

#objectAtIndexPath(indexPath) ⇒ Object



137
138
139
# File 'lib/nitron/table_view_controller.rb', line 137

def objectAtIndexPath(indexPath)
  @controller.objectAtIndexPath(indexPath)
end

#sectionForSectionIndexTitle(title, atIndex: index) ⇒ Object



141
142
143
# File 'lib/nitron/table_view_controller.rb', line 141

def sectionForSectionIndexTitle(title, atIndex:index)
  @collection.sectionForSectionIndexTitle(title, atIndex:index)
end

#sectionIndexTitlesForTableView(tableView) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/nitron/table_view_controller.rb', line 145

def sectionIndexTitlesForTableView(tableView)
  if @options[:groupIndex]
    @controller.sectionIndexTitles
  else
    nil
  end
end

#tableView(tableView, titleForHeaderInSection: section) ⇒ Object



153
154
155
156
157
158
159
160
161
# File 'lib/nitron/table_view_controller.rb', line 153

def tableView(tableView, cellForRowAtIndexPath:indexPath)
  @cellReuseIdentifier ||= "#{@className.gsub("ViewController", "")}Cell"
  unless cell = tableView.dequeueReusableCellWithIdentifier(@cellReuseIdentifier)
    puts "Unable to find a cell named #{@cellReuseIdentifier}. Have you set the reuse identifier of the UITableViewCell?"
    return nil
  end

  cell
end