ios - UITableViewDelegate and UITableViewDatasource confusion -


i understood before that
delegate pattern used invoking events delegate instance , getting controls (like size / font / etc...).

datasource pattern getting data datasource instance (like views / title / description / etc...)

but seems nice illusion, after looking apple's uitableviewdelegate protocol got confused because

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath; - (cgfloat)tableview:(uitableview *)tableview heightforheaderinsection:(nsinteger)section; - (cgfloat)tableview:(uitableview *)tableview heightforfooterinsection:(nsinteger)section; 

are delegate methods (but thinking uitableviewdatasource methods)

is dirty code apple, or i'm missing important understand difference between datasource , delegate?

edit: @dbd nice answer, here more confusion

here uitableviewdelegate method returns view drawing

 - (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section; 

and there configuration in uitableviewdatasource

 - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section; 

and oops, can see method returns view in uitableviewdatasource

 - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath; 

here have question why cellforrowatindexpath: , viewforheaderinsection: not in uitableviewdatasource

this how i've thought it.

uitableviewdatasource primary data. actual contents of table. how many rows? content of row x?

uitableviewdelegate secondary , display data. how tall should be, should display in selected state, , call backs "hey i'm something."

however admit see of fine line (and don't buy of choices)

uitableviewdatasource has titleforheaderinsection. uitableviewdelegate has viewforheaderinsection.

so if it's pure "data" title, it's data source, if includes display wrapper view, it's delegate. wait, cellforrowatindexpath view , that's part of data source, why put viewforheaderinsection in delegate? while can barely see distinction between "cell" data , "title view" delegate, think confusion of splitting "title" methods different protocols not preferable. i'm sure many might disagree me, it's opinion.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -