开发者

releasing tableHeaderView

in my code i add an UIView to my tableHeaderView.

self.tableView.tableHeaderView = containerView;

And then i need to release or disabling this one. I tried to use

[self.tableView setTableHeaderView:nil];
[tableView reloadData];

but it doesn't work, i had this error :

malloc: * error for object 0x4b1aff0:开发者_Go百科 pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

Thank's for reading,

Tommy


I got error: EXC_BAD_ACCESS when I try

[self.tableView setTableHeaderView:nil];

I changed:

dispatch_async(dispatch_get_main_queue(), ^{
   self.tableView.tableHeaderView = nil;
});

It works for me. Good luck!

P/s: I know this is old question:D


The error message says your containerView is not allocated and then when you try to set the property to nil, you get the error.


You should do something like

// First create the containerView
UIView *containerView = [UIView alloc] init..];

// Set it as the table header view (this will retain it)
[self.tableView setTableHeaderView:containerView];

// Now we're done with containerView, so release it:
[containerView release];

You could have also used

UIView *containerView = [UIView alloc] init..] autorelease];

but then you wouldn't need the last release message.

If you want to "disable" this header view, it should be enough to do what you wrote:

[self.tableView setTableHeaderView:nil];
[self.tableView reloadData];


It works for me with:

self.tableView.tableHeaderView = nil;

and also

[self.tableView setTableHeaderView:nil];

I think you may have another problem. Maybe you are releasing your containerView more than you should.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜