开发者

Rationale for design of UITableViewDataSource

开发者 https://www.devze.com 2023-02-02 09:22 出处:网络
I\'m designing an API interface for a magazine viewer. Something like iGizmo (for iPad). The view that displays a magazine is very similar to a TableView. As one can think about articles as sections a

I'm designing an API interface for a magazine viewer. Something like iGizmo (for iPad). The view that displays a magazine is very similar to a TableView. As one can think about articles as sections and pages as cells.

Because of that I'd like to expose DataSource & Delegate in the same manner as UITableView does. However I'm not entirely sure why apple designed TableView delegate/DataSource in that way it always provide the TableView as parameter in each method.

I've tried to rationalize it and I didn't find any good excuse for such api design. I'm thinking about leaving out the tableView/magazineView parameter in my API.

Do you see any good reasons behind such API design?

Wouldn't it be easier and clearer to开发者_Python百科 write methods like the one below?

– cellForRowAtIndexPath: 
– numberOfSections
– numberOfRowsInSection:
– sectionIndexTitles
– sectionForSectionIndexTitle:atIndex:
– titleForHeaderInSection:
– titleForFooterInSection:


Interesting question. Whilst this is a guess, I suspect it's there so a single data source class can be the delegate for multiple table views with differing requirements. (i.e.: It can check the tableView that's provided and respond accordingly.)

As such, if you don't ever anticipate this requirement, you could most likely omit the equivalent parameter from your method signatures.

Then again, if it's at all possible that you might want to access the "calling" magazineView, you could just leave the parameter in there - it's not as if passing a pointer around is incredibly resource inefficient.

0

精彩评论

暂无评论...
验证码 换一张
取 消