how to configure this to be rendered in a UITableView or should this be done in multiple UITableView's

本小妞迷上赌 提交于 2019-12-25 03:53:08

问题


I don't use UITableViews that much but need to in this case. I have a fairly complex Menu object. It has headers and items, like so (imagine a rails acts_as_tree where the menuHeaders array can be arbitrarily deep so there three abstractios: a Menu, a MenuHeaders array which can be nested, and a MenuItems array):

Menu
 \menuHeaders is an array
    menuHeader - name="Service"
      \menuHeaders[]
      \menuItems
        \menuItem="transmission fix"
        \menuItem="replace gaskets"
    menuHeader - name="Specials"
      \menuHeaders
          \menuHeader -name="Tires"
             \menuItem - special tire
             \menuItem - verySpecial Tire
      \menuItems
          \menuItem - name="oil change"
          \menuItem - name="windows clean"

Output in table:

Service
 transmission fix
 replace gaskets
Specials
  Tires
    special tire
    verySpecial Tire
  oil change
  windows clean   

I am not sure if I should structure this into a signle UITableView or whether each sub-array should be its own UITableView or how I would iterate over each element? It seems like the cellForRowAtIndexPath can only handle either single arrays or 2D arrays which is not what this is. How would I structure this?

When I render in jQuery I do something like

renderMenHeader(menuHeader)
  if(menuHeader.menuItems){
    for(mi in menuHeader.menuItems){
      renderMenuItem(mi)
    }
  }

  if(menuHeader.menuHeaders){
    for(mh in menuHeader.menuHeaders){
      renderMenuHeader(mh)
    }
  }

but not sure how to map this to UITableView abstraction. In all honest, I would rather jsut keep these as separate UIView's but they get up to 300-500 units so I need the ability to handle processing of only visible elements. If there is a workaroudn for handling this in generic UIView's that would also be of interest.

thx

来源:https://stackoverflow.com/questions/25373642/how-to-configure-this-to-be-rendered-in-a-uitableview-or-should-this-be-done-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!