What's the right way to add a ToolBar to a UITableView?

后端 未结 5 1075
情深已故
情深已故 2021-01-31 04:27

I\'m writing a Navigation-Based iPhone app, and I\'d like to have a UIToolBar docked at the bottom of my screen, with a UITableView scrolling between the tool bar and the naviga

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 04:55

    All you need do is implement the UITableViewDelegate and UITableViewDatasource methods required for the level of table view functionality you require. These methods can be in any class(es) though said classes should conform to the relevant protocols. The delegate and datasource should be set on the UITableView instance - either programatically or with Interface Builder. According to the docs you will lose some functionality - see the overview section.

    Personally I find that many developers seem to be obsessed with providing all of this functionality in a single monolithic view controller class, and that because they have a table view in their view then a subclass of UITableViewController must be used. However, I like to consider the Single Responsibility Principle and will often break the datasource and delegate into separate classes when the complexity is anything other than simple. The code is also then not tied to a specific UIViewController implementation.

    In situations where I have separate datasource/delegate classes I often construct and wire them up to the table view using Interface Builder and not in code. This approach (to me at least) is in the spirit of Dependency Injection and saves writing some boiler-plate code, and provides some level of decoupling.

    These choices of course are influenced by the complexity of the functionality that you are trying to achieve - for simple implementations I might find myself using UITableViewController.

提交回复
热议问题