Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-25-2010, 02:56 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 64
algor_angel is on a distinguished road
Default Using Search Bar with Multiple XIB Table View

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?
algor_angel is offline   Reply With Quote
Old 09-25-2010, 09:42 AM   #2 (permalink)
Fly-by-night Innovator
 
Join Date: Jun 2010
Posts: 364
musicwind95 is on a distinguished road
Default

I'm not sure what you're asking, so I'll cover some basics.

First, the NSMutableArray really should be an IBOutlet. It won't break anything, but it's a semantics thing.

Your use of a dictionary is complicating things. Just add the view controller itself into the views array; you can then call viewController.title. Otherwise, you'd need many dictionaries, one for each view. It gets complicated.

Try this code for the back button item:
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Title" style:UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];


To load a view from a specific XIB, try initwithNibName:bundle:
__________________
If I have helped you, please consider donating. I use PayPal. It would mean a lot to me!


For more iOS Development, check out my blog—Cups of Cocoa. All visitors welcome, but especially beginners!

Hope I have helped!

Please check out IceFall, a new action game available in the App Store!
musicwind95 is offline   Reply With Quote
Reply

Bookmarks

Tags
multiple xib, search bar, table view

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 345
9 members and 336 guests
2ndSegment, headkaze, mistergreen2011, nobstudio, Objective Zero, pungs, revg, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:07 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0