I am doing a Apple Developer Tutorial and I have a couple basic questions about the lines of code at the bottom:
-
Neither one of these lines of code alloc and init the objects that they create? Is this because the objects are assigned values at their creation?
-
The dequeueReusableCellWithIdentifier method – Is the only way that this method returns nil is if there is no cell object with the same name as the cell identifier parameter? What if there was no cell in the pool that it could reuse, does it then create one or return nil? The documentation states that the method returns – A UITableViewCell object with the associated identifier or nil if no such object exists in the reusable-cell queue.
Thanks ahead of time for the help
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row];
From the comments….
The lines of code you posted don’t actually create anything; they get references to things that have been created elsewhere. Something else — either your code or framework code — already instantiated them with alloc/init and is now giving you access.
In the table view example, if you registered a class/nib with your table view then it creates the cell for you. If not, then you create it when
dequeueReusableCellWithIdentifier:returnsnil. Either way, when it returns non-nil, that’s an object that was created at some point other than the one where your program is at that moment.(The self.dataController one isn’t something I recognize but the same logic must apply…either its list is being pre-populated by something you do earlier or it’s generating things and giving them to you as you ask.)