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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 01-20-2010, 04:43 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 9
Default Problem with didSelectRowAtIndexPath with Indexed TableView

Hi all,

I have an app with a regular TableView. When the user selects a cell, another view is brought up, that has the content of the cell as the navigationItem.Title

That worked fine.

When I tried to make the TableView into an indexed tableView the variable failed to carry through.

Here is the indexedTableView code:

Code:
- (void)viewDidLoad {

	self.navigationItem.title = @"Glossary";


	
	IndexItems = [[NSMutableArray alloc] init];
	
	
	[IndexItems addObject:@"Alpha"];
	[IndexItems addObject:@"Beta"];
	[IndexItems addObject:@"Charlie"];
	[IndexItems addObject:@"Delta"];
	[IndexItems addObject:@"Echo"];
	wordIndex = [[NSMutableArray alloc] init];
    
    for (int i=0; i<[IndexItems count]-1; i++){
        //---get the first char of each word---
        char alphabet = [[IndexItems objectAtIndex:i] characterAtIndex:0];
        NSString *uniChar = [NSString stringWithFormat:@"%C", alphabet];
        
        //---add each letter to the index array---
        if (![wordIndex containsObject:uniChar])
        {            
            [wordIndex addObject:uniChar];
        }        
    }	
	
	[super viewDidLoad];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; 
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	

	return 1;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
		
	return [wordIndex objectAtIndex:section];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
		//---get the letter in each section; e.g., A, B, C, etc.---
		NSString *alphabet = [wordIndex objectAtIndex:section];
		
		//---get all words beginning with the letter---
		NSPredicate *predicate = 
        [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
		NSArray *items = [IndexItems filteredArrayUsingPredicate:predicate];
		
		//---return the number of words beginning with the letter---
		return [items count];    
		
	}
	





- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
		return wordIndex;

}



- (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];
	}
	
	NSString *alphabet = [wordIndex objectAtIndex:[indexPath section]];
	NSPredicate *predicate = 
	[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
    NSArray *items= [IndexItems filteredArrayUsingPredicate:predicate];
    
	if ([items count]>0) {
        NSString *cellValue = [items objectAtIndex:indexPath.row];
        cell.textLabel.text = cellValue;
	}
	
	return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	NSString *selectedItem = [IndexItems objectAtIndex:indexPath.row];
	
	
	//Initialize the detail view controller and display it.
	DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
	dvController.selectedItem = selectedItem;
	[self.navigationController pushViewController:dvController animated:YES];
	[dvController release];
	dvController = nil;	

}
- (void)dealloc {
	
	[IndexItems release];
	[wordIndex release];
    [super dealloc];
}
Thanks So much in advance!!
Sentis is offline   Reply With Quote
Old 01-20-2010, 10:20 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

The presence of an index should have zero effect on didSelectRow. You are doing something else wrong.

I do notice that you have only 1 section, and that sort of defeats the purpose of having an index.

You might also want to look at the various substring options, as that would keep you from having to switch between chars and NSStrings.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Tags
indexed table, navigation, uitableview

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: 252
14 members and 238 guests
ADY, CKAmike, Dani77, dessicant, Duncan C, HemiMG, jakerocheleau, nick.keroulis, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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