Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialharpreet grewal
19,018 Pointswhy does both [self.tableView cellForRowAtIndexPath:indexPath]; and [tableView cellForRowAtIndexPath:indexPath]; work?
in the -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method why are we using [tableView cellForRowAtIndexPath:indexPath]; instead of with "self" [self.tableView cellForRowAtIndexPath:indexPath]; and why does it work either way? thanks
1 Answer
Patrick Cooney
12,216 PointsYou don't need to use self because you are inside the scope of a method that has a local variable tableView
. Because the first argument this method takes in is called tableView
that argument becomes a local variable that is available to you from within the method. Without seeing the rest of the code and knowing if there is another tableView
somewhere else in the code I'm thinking it works either way because you only have that instance of tableView
so the self
points to the same thing.