2012-01-12 1 views
1

didSelectRowAtIndexPathに問題があります。この点について他のクエリがありますが、私の問題を解決できないようです。基本的にはテーブルビューが読み込まれますが、セルがクリックされたときは何もしません。つまり、新しい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

+0

'self.navigationController'がnilでないことを確認できますか? –

+0

投稿した内容をコピーしたので、すべてself.navigationControllerの後にpushViewControllerが続きます。 – Lateralus

関連する問題