gpt4 book ai didi

ios - didSelectRowAtIndexPath 没有推送新 View

转载 作者:行者123 更新时间:2023-11-29 11:17:21 24 4
gpt4 key购买 nike

我在使用 didSelectRowAtIndexPath 时遇到问题 我知道在这一点上还有其他查询,但似乎没有一个能解决我的问题。基本上,tableview 会加载,但是当单击单元格时它不会执行任何操作,即它不会推送新的 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];
}

}

关于ios - didSelectRowAtIndexPath 没有推送新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8842212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com