1

I have a strange behavior in a table view with sections. When i scroll the table ALL sections headers stay on the position and the table view below scrolls. Only if I scroll/touch the headers both are scrolling synchronously. Any idea what is wrong here?

enter image description here

class TVController < UITableViewController

  def viewDidLoad
    super
    @sections = [{:title=>"30.03", :bookings=>["Opening Balance"]},
                 {:title=>"31.03", :bookings=>["Thai", "Coffee"]},
                 {:title=>"02.04", :bookings=>["Pizza"]},
                 {:title=>"03.04", :bookings=>["Nido, View", "Coffee ", "Withdrawel ", "Coffee "]},
                 {:title=>"07.04", :bookings=>["Mautgebühren "]},
                 {:title=>"11.04", :bookings=>["Tipp Hofer Alpl ", "Meral ", "Menterschwaige", "Eis"]},
                 {:title=>"12.04", :bookings=>["Flaucher"]},
                 {:title=>"14.04", :bookings=>["Thai "]},
                 {:title=>"25.04", :bookings=>["ATM", "Samen Schmitz", "Edeka ", "Maelu ", "Clearence"]},
                 {:title=>"26.04", :bookings=>["Auerdult ", "Schneebesen"]},
                 {:title=>"28.04", :bookings=>["Thai"]},
                 {:title=>"30.04", :bookings=>["Bahnhof "]},
                 {:title=>"05.05", :bookings=>["Thai"]},
                 {:title=>"07.05", :bookings=>["Valleys "]},
                 {:title=>"10.05", :bookings=>["Café "]}]

    @table = UITableView.alloc.initWithFrame(self.view.bounds, style:UITableViewStyleGrouped)
    @table.dataSource = self
    @table.delegate = self
    self.view.addSubview @table
  end

  def tableView(tableView, cellForRowAtIndexPath: indexPath)
    @reuseIdentifier ||= 'ACCOUNT_TABLE_CELL'
    cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier) || begin
      UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:@reuseIdentifier)
    end
    cell.textLabel.text = self.booking(indexPath)
    cell
  end

  def numberOfSectionsInTableView(tableView)
    self.sections.length
  end

  def tableView(tableView, numberOfRowsInSection: section)
    self.sections[section][:bookings].length
  end

  def tableView(tableView, titleForHeaderInSection: section)
    self.sections[section][:title]
  end

  def booking(indexPath)
    @sections[indexPath.section][:bookings][indexPath.row]
  end
end
Kai Mysliwiec
  • 354
  • 4
  • 11
  • This is expected behavior. For a workaround see http://stackoverflow.com/questions/664781/change-default-scrolling-behavior-of-uitableview-section-header?rq=1 – JRG-Developer May 15 '15 at 07:59
  • I don't think this is expected because it looks really wired. All section headers stay on their position, not only the first one on the top. They scroll together with the table view only if i scroll by touching the headers itself. – Kai Mysliwiec May 15 '15 at 11:26

2 Answers2

0

If I am understanding your scenario correctly (pardon me if I am not):

Purpose of headers in table view is the one that is currently happening with you. Headers are supposed to be present in the view at the top of rows, until all rows of that headers are scrolled, once all the rows are scrolled, header moves its self as well.

If you want to scroll header along with the rows, they you should actually consider making a row for that purpose and not a header, thus not creating any sections.

If you want to do it using headers then follow the link "JRG-Developer" already provided : Change Default Scrolling Behavior of UITableView Section Header

But, if you are trying to create normal scrolling away headers like rows, then I would recommend to use rows for that purpose and create a custom row to fulfill the purpose of that header.

Community
  • 1
  • 1
Abdul91
  • 708
  • 5
  • 16
  • I just want the normal behavior where only **one** header stays and all others are moving with the tableView. Please look at the screenshot. Anyway the problem was I had two tableViews because I was inheriting from UITableViewController. One tableView was scrolling and the other not. Thanks anyway! – Kai Mysliwiec May 15 '15 at 19:19
0

Answer by caram in the RubyMotion Motion forum

If you inherit from UITableViewController, self.view is already a tableView, so you end up with 2 tableView. Just delete @table = UITableView.alloc.init...

http://community.rubymotion.com/t/uitableview-sections-headers-dont-scroll-synchronously/525

Kai Mysliwiec
  • 354
  • 4
  • 11