nik
nik

Reputation: 1574

Default call to UITableViewDataSource/Delegate methods

I have added a table view to a view controller but haven't connected the data source and delegate to that view controller. So in that case is there any default implementation of those required methods (of UITableViewDataSource/Delegate) that gets called? The program is not crashing and not showing any data as well.

Upvotes: 0

Views: 68

Answers (1)

rmaddy
rmaddy

Reputation: 318854

A UITableView with no delegate and no data source will simply show an empty table. It won't crash but it's useless since you don't provide any data.

By default a table view shows one section with zero rows. That is why it doesn't crash. If you read the documentation for UITableViewDataSource you will see that numberOfSectionsInTableView: has a default value of 1. Without a data source, the table assumes 0 rows for the section.

Many of the UITableViewDelegate methods also assume an appropriate default value.

Upvotes: 2

Related Questions