GeneralMike
GeneralMike

Reputation: 3001

Do I have to explicitly call setDelegate: and setDatasource: for a UITableView that is a property of my UIViewController?

Background first: I had a UIViewController with 3 working UITableViews. I added a fourth table, but my controller never called any of the UITableViewDelegate or UITableViewDataSource methods (like tableView:cellForRowAtIndexPath, for example) for my fourth table, only for the first three. After much weeping and gnashing of teeth, I figured out I needed to call [self.myFourthTable setDelegate:self] and [self.myForthTable setDelegate:self] in my viewDidLoad.

I never called either of these methods for my first 3 tables. What's going on here? Why did I have to call these for my fourth table, and not for the first three? As far as I can tell, the fourth should be treated the same way as the first three - they are all properties of my view controller, they are all synthesized together, and I address them the same way in my code.

Upvotes: 0

Views: 154

Answers (1)

MarkPowell
MarkPowell

Reputation: 16540

My guess is these UITableViews are added in Interface Builder. The first three has their datasource and delegate set via outlets in Interface Builder. You didn't do that with the forth, so needed to do it via code.

screenshot example

Upvotes: 2

Related Questions