In a simple UITableView I have:
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc]initWithObjects:@"Pictures",@"Video",@"Text",@"Map",nil];
self.selectionList = array;
[array release];
[super viewDidLoad];
}
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [selectionList objectAtIndex:row];
return cell;
}
My question is this, why in the viewDidLoad section, does it need to be self.selectionList and not just selectionList?? I mean, the whole point is to pass the contents of the array we just created into the selectionList array, so why the self?
Whenever you use ‘self’ it will use the property setter and getter. That means that if you create a property as being retain it will allow you to
release(as the setter will call aretain). If you didn’t use the setter (I’m assuming that it is a retain property), you could also write the above like this (but I wouldn’t recommend it):