Hi,
I have been reading a lot through the internet, and found out that when you use arrays and such in a navigation controller, in the long run it will save time etc. I have always been using the navigation controller and different views and linked them together like this.
Code:
#import <UIKit/UIKit.h>
#import "View1.h"
#import "View2.h"
#import "View3.h"
@interface RootViewController : UITableViewController {
View1 *v1;
View2 *v2;
View3 *v3;
}
@property(nonatomic,retain) View1 *v1;
@property(nonatomic,retain) View2 *v2;
@property(nonatomic,retain) View3 *v3
@end
and then in my .m file:
Code:
#import "RootViewController.h"
@implementation RootViewController
@synthesize v1;
@synthesize v2;
@synthesize v3;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Home";
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.row == 0) {
[cell setText:@"About"];
}
etc.
etc.
return cell;
}
...
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
if(self.v1 == nil) {
View1 *myview =
[[About alloc] initWithNibName:@"About" bundle:[NSBundle mainBundle]];
self.v1 = myview;
[myview release];
}
[self.navigationController pushViewController:self.v1 animated:YES];
}
etc.
etc.
}
}
...
@end
This just gets really tiring really fast. My question is: What are the advantages of doing it a different way? And how many different ways are there even, that would be suitable?
Thanks in advance,