UITableView which has sections as alphabets and various rows within each section
Posted
by
lifemoves
on Stack Overflow
See other posts from Stack Overflow
or by lifemoves
Published on 2011-01-12T20:51:40Z
Indexed on
2011/01/12
20:53 UTC
Read the original article
Hit count: 132
iphone
Hello
I have a database in which I am inserting data by parsing an XML document. Populating the data using Navigation bar control view. I have various NSObjects defined in a class and have populated the data using NSMutableArray. Using UITableview I have populated the data.
My question is : I have populated the data with the sections defined in it as alphabets so I have total of 26 sections. Each section has data in form of name. Now when I use cellforrowatIndexpath it does not give me the correct index for row and section together. My code is :
(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]; }
/* Index names as in AB ....Z */
NSString *strIndexNames = [arrCharacters objectAtIndex:indexPath.section];
/* object sections has names in each section */
NSArray *arrIndexedCategories = [objSections objectForKey:strIndexNames]; NSString *strName = [arrIndexedCategories objectAtIndex:indexPath.row] ;
cell.textLabel.text = strName;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.textLabel.font = [UIFont systemFontOfSize:16];
return cell; }
Any help whatsoever will be really helpful.
S
© Stack Overflow or respective owner