在Iphone sdk中的UIBarButtonItem中获取内存分配问题

时间:2010-03-27 11:45:23

标签: objective-c

这里我在UIBarButtonItem遇到内存分配问题,相关代码是:

  toolbar = [UIToolbar new];
  toolbar.barStyle = UIBarStyleBlackOpaque;
  [toolbar setFrame:CGRectMake(0, 350,320,20)];
  [self.view addSubview:toolbar];

  UIBarButtonItem* barItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(categoryConfig:)]  ;

  rightBarItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(dialogOtherAction:)]  ;

  UIBarButtonItem* barItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(categoryConfig:)]  ;

  NSArray *items = [NSArray arrayWithObjects: barItem1,rightBarItem,barItem2, nil];

  [barItem1 release];
  [barItem2 release];
  [rightBarItem release];
  [toolbar setItems:items animated:NO];

将UIBarButtonItems添加到我释放它们的数组项中之后。尽管它在barbuttons处显示了分配。

可以帮我吗?

谢谢你, Monish。

1 个答案:

答案 0 :(得分:0)

您使用toolbar分配了toolbar = [UIToolbar new];,因此您需要将其释放。