0

我这样声明我的表:

    CGRect cgRct = CGRectMake(5, 5, 310, 363);
videoTable = [[UITableView alloc] initWithFrame:cgRct style:UITableViewStylePlain];
videoTable.backgroundColor = [UIColor clearColor];
videoTable.separatorColor = [UIColor whiteColor];
videoTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
videoTable.dataSource = self;
videoTable.delegate = self;
videoTable.alwaysBounceVertical = NO;
videoTable.bounces = NO;
videoTable.allowsSelection = YES;
//self.videoTable.layer.zPosition = -1;
//table.dragging = NO;
[self.view addSubview:videoTable];

当我们离开视图时,我删除了我的桌子

-(void) viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
NSLog(@"*viewDidDisappear");
if (videoTable)
{
    NSLog(@"removing table");
    [videoTable removeFromSuperview];
    videoTable.delegate = nil;
    [videoTable release];
   // self.videoTable = nil;
}
}

当视图再次加载时,没有表格的迹象,但是..它仍然存在,因为

-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self populateFileList];

if (videoTable)
{
    NSLog(@"table still here");
}
else
{
    NSLog(@"No table");
}
}

谁能解释我错过了什么?我希望表完全消失,所以我可以分配一个新表。

非常感谢,-代码

4

3 回答 3

1

您需要在释放后将 nil 分配给表,否则该变量仍然有一个值(对表对象的旧引用):

[videoTable release];
videoTable = nil;
于 2012-04-19T20:00:12.070 回答
0

如果 videoTable 不同于 nil,则 if (videoTable) 为真。因此,您需要在释放表后将其分配为零。

于 2012-04-19T20:15:14.050 回答
0

你可以试试这个:

-(void)viewDidUnload{
    [super viewDidUnload];
    [self setVideoTable:nil];
}
于 2012-04-19T20:05:31.290 回答