2011-11-23 30 views
0

我正在尝试为我的UINavigationController的rightBarButtonItem创建一个设置图标。在我的应用程序:DidFinishLaunching,我创建按钮,并设置它UITableView的数据被更改

//pseudo code for applicationdidfinish launching 

HomeController *home = [[HomeController alloc] init]; // root view of my UINavigationController 
home.navigationItem.rightBarButtonItem = settingsBarButtonItem; 
[settingsButton addTarget:self action:@selector(settingsPressed:) forControlEvents:UIcontrolEventTouchUpInside]; // i used a button for the barbuttonitem to not get the bar button item border 

比settingsPressed:

SettingsController* settings = [[SettingsController alloc] initWithNibName:@"SettingsController" bundle:nil]; 
    UINavigationController* popoverNav = [[UINavigationController alloc] initWithRootViewController:settings]; 
    [settings release]; 
    popover = [[UIPopoverController alloc] initWithContentViewController:popoverNav]; 
    [popoverNav release]; 
    // show settings 
    if ([popover isPopoverVisible]) { 
     [popover dismissPopoverAnimated:YES]; 
    } else { 
     [popover presentPopoverFromBarButtonItem:bbiSettings permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
    } 
在SettingsController

,在viewDidLoad中:

NSArray *array = [NSArray arrayWithObjects:@"one", @"two", @"three", nil]; 
self.DataArray = array; // (nonatomic, retain) 
[array release]; 

我不显示此阵列马上。像iPhone设置应用程序一样,当他们点击我的分组表格中的一个单元格时,它会打开一个新的UITableView。因此,在这种UITableView的,在的tableView:numberOfRowsInSection:方法,我

return [self.DataArray count]; 

然而,正是在这里,我的应用程序崩溃。当我看着我的数组时,我现在有一些随机的东西,比如vl.proj,有时候,UIViews等等。我不知道为什么这个数组会被改变。我不知道是不是因为我从applicaionDelegate调用popover,我通常不会这样做,那就是问题所在,或者是否有其他问题。谢谢。

+0

什么属性设置为DataArray变量 – iOSPawan

+0

@ pawan.mangal非原子,保留 –

+0

它被改变因为它的释放某处,你的指针指向一个新的对象 –

回答

1

[NSArray arrayWithObjects:]返回一个自动释放数组。所以你不必手动发布它。你可以删除这行[array release];在viewDidLoad中,一切都应该正常工作。