Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Chapter 8: View Tag vs outlet

In Chapter 8, we use View Tag for the table view. Could we just use outlet as we did before: 

@property (weak, nonatomic) IBOutlet UITableView *tableView;
and then 

[self.tableView registerClass:[BIDNameAndColorCell class] forCellReuseIdentifier:CellTableIdentifier];


instead of 

UITableView *tableView = (id)[self.view viewWithTag:1]; 

[self.tableView registerClass:[BIDNameAndColorCell classforCellReuseIdentifier:CellTableIdentifier];


If we could, what are the advantages of using Tag then?

Comments

  • You are correct. Using an outlet is preferred over finding a view by tag, less fragile. 

    Using tags is quite useful when adding views dynamically in a way that can not be predicted at design time, for example for user created content. This is not such a case and will be updated for future editions.

    // Fredrik
Sign In or Register to comment.