views:

112

answers:

2

Hi All,

Ive been trying to push a new view when a cell is tapped but absolutely nothing happens. I figured grouped style pushed the same as plain. Here is my code:

-(void)viewDidLoad {
[super viewDidLoad];
contactArray = [[NSArray alloc] initWithObjects:@"iPhone",@"iPod",@"MacBook",@"MacBook     Pro",nil];
shareArray = [[NSArray alloc] initWithObjects:@"Flex",@"AIR",@"PhotoShop",@"Flash",nil];

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}


// Customize the number of rows in the table view.
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0)
    return [contactArray count];
else
    return [shareArray count];
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if(section == 0){
    return @"Contact";
}else{
    return @"Share";
}
}

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
if(section == 0){
    return @"Footer for Apple Products";
}else{
    return @"Footer for Adobe Softwares";
}
}


// 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...
if(indexPath.section == 0){
    cell.text = [contactArray objectAtIndex:indexPath.row];
}else{
    cell.text = [shareArray objectAtIndex:indexPath.row];
}
return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//NextViewController *nextController = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil];
//[self.navigationController pushViewController:nextController animated:YES];
if([contactArray objectAtIndex:indexPath.row] == @"iPhone"){
    LandscapeHydrogen *abo = [[LandscapeHydrogen alloc] initWithNibName:@"LandscapeHydrogen" bundle:nil];
[self.navigationController pushViewController:abo animated:NO];
[abo release];
}
}

Any help is appreciated.

+2  A: 

You could put a breakpoint at the didSelectRowAtIndexPath to see if the if statement is true.

Try changing

if([contactArray objectAtIndex:indexPath.row] == @"iPhone"){

to

if([[contactArray objectAtIndex:indexPath.row] isEqualToString:@"iPhone"]){
Rengers
Still Nothing, Debugger says mach msg trap
Tanner
Where did you set the breakpoint? Set it at the if statement and step over each line to see how the code executes.
Rengers
I set it right on the if statement inside didselectrowatindexpath method. Nothing was displayed in the debugger but the red arrow did go through the entire method like it would normally. If you know any other way to make a grouped table push any view, that would work. I just need it to push a few different views depending on whats selected.
Tanner
Solved with else if (indexPath.section == 1 [self.navigationController pushViewController:nextController animated:YES];
Tanner
A: 

Solved with else if (indexPath.section == 1 & indexPath.row == 0){ FaceBook *nextController = [[FaceBook alloc] initWithNibName:@"FaceBook" bundle:nil]; [self.navigationController pushViewController:nextController animated:YES];

Tanner