didSelectRowAtIndexPath未推送新视图



我的didSelectRowAtIndexPath有问题。我知道在这一点上还有其他查询,但似乎没有一个能解决我的问题。基本上,表视图加载,但当单击单元格时它什么也不做,即它不做;t推动新的xib。任何帮助都会很棒。

@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    

NSString上的isEqual:方法执行指针比较,而不是字符串实际内容之间的比较。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];
    }
 }

最新更新