请参阅以下代码我想知道我该如何解除分配单元格。根据我的理解,每个保留的每个分配和释放必须有一个解除分配。下面如何在目标C中释放和释放这些变量?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"UITableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle: UITableViewCellStyleSubtitle
reuseIdentifier: CellIdentifier] autorelease];
}
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row]; return cell;
}
,并从代码我在做正确的事情去页头dataArray的或者它应该被释放或两者。
接口
@interface myViewController : UIViewController
{
NSArray *dataArray;
}
@property(retain,nonatomic) NSArray *dataArray;
@end
从实施
- (void)viewDidLoad
{
[super viewDidLoad];
self.dataArray=[[NSArray alloc] initWithObjects:@"XXX",@"YYY",@"ZZZ",nil];
}
- (void)viewDidUnload
{
[super viewDidUnload];
[self.dataArray dealloc];
}