2012-01-12 57 views
1

我遇到了didSelectRowAtIndexPath問題我知道在這一點上還有其他疑問,但沒有一個似乎解決了我的問題。基本上tableview會加載,但單擊單元格時它不會做任何事情,即它不會推送新的xib。任何幫助都會很棒。didSelectRowAtIndexPath不推送新視圖

@implementation ViewController 
@synthesize TableViewControl; 
@synthesize tableList; 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.title = @"The Bird Watching App"; 
    // Do any additional setup after loading the view, typically from a nib. 


    tableList = [[NSMutableArray alloc] initWithObjects:@"Map",@"My Profile",@"Bird Info", nil]; 



    TableViewControl.dataSource = self; 
    TableViewControl.delegate = self; 

} 

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    if ([[ tableList objectAtIndex:indexPath.row] isEqual:@"Map"]) 
    { 
     Map *map = [[Map alloc] initWithNibName:@"Map" bundle:nil]; 
     [self.navigationController pushViewController:map animated:YES]; 

    } 

    else if ([[ tableList objectAtIndex:indexPath.row] isEqual:@"My Profile"]) 
    { 
     MyProfile *myprofile = [[MyProfile alloc] initWithNibName:@"My Profile" bundle:nil]; 
     [self.navigationController pushViewController:myprofile animated:YES]; 
    } 

    else if ([[ tableList objectAtIndex:indexPath.row] isEqual:@"Bird Info"]) 
    { 
     BirdInfo *birdinfo = [[BirdInfo alloc] initWithNibName:@"Bird Info" bundle:nil]; 
     [self.navigationController pushViewController:birdinfo animated:YES]; 
    } 

}  


@end  

回答

2

NSStringisEqual:方法執行指針比較和字符串的實際內容之間不進行比較。您的if語句需要使用isEqualToString:進行適當的比較。

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    if ([[ tableList objectAtIndex:indexPath.row] isEqualToString:@"Map"]) 
    { 
     Map *map = [[Map alloc] initWithNibName:@"Map" bundle:nil]; 
     [self.navigationController pushViewController:map animated:YES]; 

    } 

    else if ([[ tableList objectAtIndex:indexPath.row] isEqualToString:@"My Profile"]) 
    { 
     MyProfile *myprofile = [[MyProfile alloc] initWithNibName:@"My Profile" bundle:nil]; 
     [self.navigationController pushViewController:myprofile animated:YES]; 
    } 

    else if ([[ tableList objectAtIndex:indexPath.row] isEqualToString:@"Bird Info"]) 
    { 
     BirdInfo *birdinfo = [[BirdInfo alloc] initWithNibName:@"Bird Info" bundle:nil]; 
     [self.navigationController pushViewController:birdinfo animated:YES]; 
    } 

} 
+0

謝謝你的回覆馬克。剛剛試過,但仍然是同樣的問題:( – Lateralus 2012-01-12 21:36:10

+0

你可以確認'self.navigationController'不是零? – 2012-01-12 21:37:29

+0

我複製你發佈的所以所有self.navigationController後面pushViewController .. – Lateralus 2012-01-12 21:41:06

相關問題