开发者

UITableView leaking?

I have a UITableViewController and I set some properties in the viewDidLoadMethod like so:

- (void)viewDidLoad {
  开发者_StackOverflow社区  [super viewDidLoad];

    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self.parentViewController.parentViewController action:@selector(dismissSettings)] autorelease];
    [self setTitle:@"Gabbai Settings"];

    //Set up the table 
    [self.tableView initWithFrame:self.tableView.frame style:UITableViewStyleGrouped];

    [self.tableView setRowHeight:65.0];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLineEtched];

    [self.tableView.backgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@_settings", kTheme] ofType:@"png"]]]];


}

The app shows a UIScrollViewController and a UIButton. When the button is pressed, the app displays a modal UINavigationController and that UINavigationController contains a UITableViewController.

For some reason, Leaks reports some leakage when I show the UITableViewController. However, if I comment out the four lines after //Set up the table, everything is fine.

When the four lines are uncommented, the Leaks instrument shows the following:

UITableView leaking?

I'm not sure what is going on here, but it's really annoying. I've used the same four lines of code before to customize my UITableViewController and this is a new behavior.

What could be wrong?


Explicitly release tableView in your dealloc method and see what happens.

Or better yet, clean all -> Build and Analyze, tell us what you see


As has been pointed out by other answers, your problem is the line:

[self.tableView initWithFrame:self.tableView.frame style:UITableViewStyleGrouped];

It will create a new UITableView object and it will not modify self.tableView which means that line is totally pointless. It only creates the leak you are experiencing. Remove it and you should be fine.


if self.tableview already exists, you don't want to initialize it again. Either initialize it once (which I'm guessing you already did, maybe by loading from a nib) and then if need be, reset the frame here.

Or just alloc/init the tableview here.


Maybe you can try defining the uiBarButtonItem as a variable, then assign it to the navigation left bar button item and then release the button

Have you try build & analyze under the Build menu? With 2.0 Objective C sentences its pretty accurate

in addition, you have to be careful with property definition, you are using self.tableView, I assume you you have something like @property(nonatomic, retain)?, in that case, once you alloc, you should release the property in the next line..

Finally, this line is extremely weird: [self.tableView initWithFrame:self.tableView.frame style:UITableViewStyleGrouped]; you are trying to initialize a table thats already initialized, because if you don't, self.tableView.frame should be in error. In addition to that, the initWithFrame method returns something that is not being assigned.. I think that you can think a better way to do this

Sorry about the mess, I've been answering this question in the chat, but unfortunately you were disconnected.

Hope this helps.


Looks like you have an array or dictionary thats leaking, not the tableview.

What is the array that you are using to fill your tableview?

Also, you wont want to [self.tableVIew initWithFrame, try [self.tableView setFrameCGRectMake(x,y,w,h)];

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜