In my table view i need to display Contact name, Company name and Picture of contact person.
I can add/edit a contact from the Add/Edit Contact page.
When I entered values in add/edit page I store them in a dictionay.
I retrieved ContactNames in an array ContactsArray and using this array I tried to set sections and headers.
in this process other fields are not displayed what we have saved, observe detail Text label even this problem in didSelectRow method also..
When I selected 1st row of any section it navigates to the details page for 1sr row of 1st section
When I selected 2nd row of any section it navigates to the details page for 2nd row of 1st section
it may be the problem of sections
//Inside ViewDidLoad Method
sections = [[NSMutableDictionary alloc] init]; ///Global Object
BOOL found;
for (NSString *temp in contactsArray)
{
NSString *c = [temp substringToIndex:1];
found = NO;
for (NSString *str in [sections allKeys])
{
if ([str isEqualToString:c])
{
found = YES;
}
}
if (!found)
{
[sections setValue:[[NSMutableArray alloc] init] forKey:c];
}
}
for (NSString *temp in contactsArray)
{
[[sections objectForKey:[temp substringToIndex:1]] addObject:temp];
}
[contactsTable reloadData];
}
Tableview methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[sections allKeys]count];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[sections valueForKey:[[[sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:section]] count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* CellIdentifier = @"Cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == Nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSString *titleText = [[sections valueForKey:[[[sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.textLabel.text = titleText;
Contact *contact = [storedContactsArray objectAtIndex:indexPath.row];
Contact *contactPicture = [storedPicsArray objectAtIndex:indexPath.row];
_____________________________________
cell.detailTextLabel.text = contact.companyName;
UIImage *contactImage = [[UIImage alloc]initWithContentsOfFile:contactPicture.contactImage];
cell.imageView.image = contactImage;
_______________________________
return cell;
}
Even when I sect Bb it navigates to hte AAAAA page details..
I tried with this link http://www.devx.com/wireless/Article/43374/0/page/2 alsoo even I repeats the same issue
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
EditContact *editContact = [[EditContact alloc] init];
if([self.storedContactsArray count] != 0)
{
Contact *contactsDict = [storedContactsArray objectAtIndex:indexPath.row];
editContact.contactInfo = contactsDict;
Contact *picsDict = [storedPicsArray objectAtIndex:indexPath.row];
editContact.storedPicsDict = picsDict;
}
[self.navigationController pushViewController:editContact animated:YES];
[editContact release];
[storedContactsArray release];
}