2010-05-04 2 views
0

Ive пытался нажать новый вид, когда камера прослушивается, но абсолютно ничего не происходит. Я понял, что сгруппированный стиль толкает то же самое, что и на равнине. Вот мой код:Как вы можете нажимать новый вид с помощью сгруппированной таблицы?

-(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]; 
} 
} 

Любая помощь приветствуется.

ответ

0

решаемые с

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

Вы можете поставить точку останова на didSelectRowAtIndexPath, чтобы проверить, истинна ли инструкция if.

Try изменения

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

в

if([[contactArray objectAtIndex:indexPath.row] isEqualToString:@"iPhone"]){ 
+0

до сих пор ничего, Debugger говорит маш тзд ловушка – Tanner

+0

Где установить точку останова? Установите его в инструкции if и перейдите по каждой строке, чтобы увидеть, как выполняется код. – Rengers

+0

Я установил его прямо в выражении if внутри метода didselectrowatindexpath. В отладчике ничего не отображалось, но красная стрелка прошла весь метод, как обычно. Если вы знаете какой-либо другой способ сделать сгруппированную таблицу нажатием любой точки зрения, это сработает. Мне просто нужно нажать несколько разных взглядов в зависимости от выбранного. – Tanner

1
YourNextViewController * nextViewController = [[YourNextViewController alloc] initWithNibName: @"YourNextViewController" bundle: nil]; 

switch (indexPath.section) { 
    case 0: 
     nextViewController.title = [_contactArray objectAtIndex: [indexPath row]]; 
     break; 

    case 1: 
     nextViewController.title = [_shareArray objectAtIndex: [indexPath row]]; 
     break; 

    default: 
     break; 
} 

[[self navigationController] pushViewController:nextViewController animated:YES]; 
} 
Смежные вопросы