didSelectRowAtIndexPath не выдвигает новое представление - PullRequest
1 голос
/ 13 января 2012

У меня проблема с didSelectRowAtIndexPath. Я знаю, что есть другие запросы на этот счет, но, похоже, ни один из них не решил мою проблему. В основном таблица загружается, но она ничего не делает при нажатии на ячейку, т. Е. Она не выдвигает новую 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    

1 Ответ

2 голосов
/ 13 января 2012

Метод isEqual: для NSString выполняет сравнение указателей, а не сравнение фактического содержимого строки. Ваши заявления 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];
    }

 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...