Reputation: 878
I'm trying to create a Settings icon for the rightBarButtonItem for my UINavigationController. In my application:DidFinishLaunching, I create the button, and set it
//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
than in 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];
}
in SettingsController, in viewDidLoad:
NSArray *array = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
self.DataArray = array; // (nonatomic, retain)
[array release];
I do not show this array right away. Like the iPhone Settings app, when they click on one of the cells in my Grouped Table, it opens up a new UITableView. So in that UITableView, in the tableView:numberOfRowsInSection: method, I
return [self.DataArray count];
However, it is here that my app crashes. When I look at my array, I now have random stuff in there, like vl.proj sometimes, UIViews, etc. I do not know why this array gets changed. I do not know if it's because I'm calling the popover from the applicaionDelegate which I normally do not do and that is the problem, or if there is something else wrong. Thanks.
Upvotes: 0
Views: 91
Reputation: 3104
[NSArray arrayWithObjects:] returns an autoreleased array. So you don't have to release it manually. You can just remove the line [array release]; in viewDidLoad and everything should work fine.
Upvotes: 1