Hi there!
I have a question for you. I hope you will answer me soon
What I am trying to accomplish is this: I started a Navigation Based App project and I'm using the following code to use multiple XIB files for each Row and would like to divide the rows in sections add a Search Bar:
.h
Code:
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController {
IBOutlet NSMutableArray *views;
}
@property (nonatomic, retain) IBOutlet NSMutableArray *views;
@end
.m
Code:
#import "RootViewController.h"
#import "FirstController.h"
@implementation RootViewController
@synthesize views;
- (void)awakeFromNib {
views = [ [NSMutableArray alloc] init];
// allocate a set of views and add to our view array as a dictionary item
FirstController *firstController = [[FirstController alloc] init];
firstController.title = @"First";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"FirtControllerTitle", @"title",
firstController, @"controller",
nil]];
[firstController release];
// Same code for Controller 2 to Controller N
// create a custom navigation bar button and set it to always say "Back"
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
// set the title of the main view
self.title = @"JGD Basic";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [views count];
}
// 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] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
cell.text = [[views objectAtIndex:indexPath.row] objectForKey:@"title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
UIViewController *targetViewController = [[views objectAtIndex: indexPath.row] objectForKey:@"controller"];
[[self navigationController] pushViewController:targetViewController animated:YES];
}
- (void)dealloc {
[views dealloc];
[super dealloc];
}
@end
I've tried to take a look at some tutorial but no one explains how to do that properly when you have multiple XIBs, otherwise I know how to do that with a single XIB for every row. I've already tried to implement some code here to add the search bar but it didn't worked. So, how do I do that?