I apologize for my issue being too elementary and if my title is misleading. I am very new to iPhone programming. I only know what Ive read and seen and my first app isnt working. I'm only trying to transition from view to view sequentially.
I have four ViewController files: RootViewController.xib, SecondList.xib, AddNewList.xib, AddNewItem.xib
Of course, RootViewController.xib loads first. There is a plus button that pushViewController AddNewList.xib. There is a Round Rect button that pushViewController SecondList.xib and lastly, a plus button pushViewControllers AddNewItem.xib.
The lastly is where the app dies. When I hit the last plus button, the program gets a GDB: Program received signal: SIGABRT. I think its caused by a memory leak. When debugging, I noticed that the method (void)dealloc; never gets executed.
Am I correct that I have a memory leak? If it is a leak, I am assuming that if the dealloc method gets executed then the leak would go away. How do I cause the dealloc method to get executed. If not a leak, what do you think?
Any suggestions would be greatly appreciated. Thanks!
My code are below:
RootViewController.h:
RootViewController.m:
AddNewSecondList.h:
AddNewSecondList.m:
SecondList.h:
SecondList.m:
I have four ViewController files: RootViewController.xib, SecondList.xib, AddNewList.xib, AddNewItem.xib
Of course, RootViewController.xib loads first. There is a plus button that pushViewController AddNewList.xib. There is a Round Rect button that pushViewController SecondList.xib and lastly, a plus button pushViewControllers AddNewItem.xib.
The lastly is where the app dies. When I hit the last plus button, the program gets a GDB: Program received signal: SIGABRT. I think its caused by a memory leak. When debugging, I noticed that the method (void)dealloc; never gets executed.
Am I correct that I have a memory leak? If it is a leak, I am assuming that if the dealloc method gets executed then the leak would go away. How do I cause the dealloc method to get executed. If not a leak, what do you think?
Any suggestions would be greatly appreciated. Thanks!
My code are below:
RootViewController.h:
Code:
#import <UIKit/UIKit.h>
#import "AddNewSecondList.h"
@interface RootViewController : UITableViewController {
AddNewSecondList *addSecondListController;
NSArray *mainList;
}
@property (nonatomic,retain) AddNewSecondList *addSecondListController;
@property (nonatomic,retain) NSArray *mainList;
-(void)addSecondList;
@end
RootViewController.m:
Code:
@implementation RootViewController
@synthesize addSecondListController;
@synthesize mainList;
- (void)viewDidLoad {
self.navigationItem.title = @"Main";
[super viewDidLoad];
UIBarButtonItem *plusButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addSecondList)];
self.navigationItem.rightBarButtonItem = plusButton;
self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
- (void)addSecondList {
if (self.addSecondListController == nil) {
AddNewSecondList *SecondListViewController = [[AddNewSecondList alloc] initWithNibName:@"AddNewSecondList"
bundle:nil];
self.addSecondListController = SecondListViewController;
[SecondListViewController release];
[self.navigationController pushViewController:self.addSecondListController animated:YES];
}
else {
[self.navigationController pushViewController:self.addSecondListController animated:YES];
}
}
- (void)dealloc {
[addSecondListController dealloc];
[mainList dealloc];
[super dealloc];
}
@end
AddNewSecondList.h:
Code:
#import <UIKit/UIKit.h>
#import "SecondList.h"
@interface AddNewSecondList : UIViewController {
SecondList *newSecondListController;
}
@property (nonatomic,retain) SecondList *newSecondListController;
- (IBAction) addndisplayNewSecondList:(id) sender;
@end
AddNewSecondList.m:
Code:
@implementation AddNewSecondList
@synthesize amount;
@synthesize newSecondListController;
- (IBAction) addndisplayNewSecondList:(id) sender {
if (self.newSecondListController == nil) {
SecondList *SecList = [[SecondList alloc]
initWithNibName:@"SecondList"
bundle:nil];
self.newSecondListController = SecList;
[SecList release];
[self.navigationController pushViewController:self.newSecondListController animated:YES];
}
else {
[self.navigationController pushViewController:self.newSecondListController animated:YES];
}
}
- (void)viewDidLoad {
self.navigationItem.title = @"New Second List";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[super viewDidLoad];
}
- (void)dealloc {
[newSecondListController dealloc];
[super dealloc];
}
@end
SecondList.h:
Code:
#import <UIKit/UIKit.h>
#import "AddNewItem.h"
@interface SecondList : UIViewController {
AddNewItem *AddNewItemViewController;
}
@property (nonatomic,retain) AddNewItem *AddNewItemViewController;
- (void)addNewListItem:(id) sender;
@end
SecondList.m:
Code:
@implementation SecondList
@synthesize AddNewItemViewController;
- (void)viewDidLoad {
self.navigationItem.title = @"Second List";
UIBarButtonItem *plusButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewPurchase)];
self.navigationItem.rightBarButtonItem = plusButton;
self.navigationItem.leftBarButtonItem = self.editButtonItem;
[super viewDidLoad];
}
- (void)addNewPurchase:(id) sender {
if (self.AddNewItemViewController == nil) {
AddNewItem *newItem = [[AddNewItem alloc]
initWithNibName:@"AddNewItem"
bundle:nil];
self.AddNewItemViewController = newItem;
[newItem release];
[self.navigationController pushViewController:self.AddNewItemViewController animated:YES];
}
else {
[self.navigationController pushViewController:self.AddNewItemViewController animated:YES];
}
}
- (void)dealloc {
[AddNewItemViewController dealloc];
[super dealloc];
}