小编Mas*_*gre的帖子

UITableView仅在第二次尝试时将数据发送到Detail View Controller

嘿,我已经在一段时间内处理过境应用程序,并且已经暂时解决了这个问题.

我正在使用iOS 5和故事板.基本上我有一个UITableView,当用户选择我使用的行时,它显示最喜欢的公共汽车站位置:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Favorite *favorite = [self.favoriteItems objectAtIndex:indexPath.row];

    stopString = favorite.title;
    routeString = favorite.subtitle;
}
Run Code Online (Sandbox Code Playgroud)

使用用户选择的单元格的停止和路径信息然后准备与我的故事板上的segue相对应的segue,推送使用停止名称和路径名称的详细视图控制器以显示来自plist的时间.

我对Objective C和iOS相当新,所以我使用的是我朋友告诉我的segue,但是,它可能是问题所在.segue看起来像这样:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    UIViewController *destination = segue.destinationViewController;
    if ([destination respondsToSelector:@selector(setDelegate:)])
    {
        [destination setValue:self forKey:@"delegate"];
    }
    if ([destination respondsToSelector:@selector(setSelection:)])
    {
        NSString *route = routeString;
        NSDictionary *selection1 = [NSDictionary dictionaryWithObjectsAndKeys:route, @"route", stopString, @"stop", nil];
        [destination setValue:selection1 forKey:@"selection"];
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的DetailViewController中的segue之后,我在视图DidLoad中获取停止和路由信息:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    route = …
Run Code Online (Sandbox Code Playgroud)

storyboard uitableview ios ios5 segue

2
推荐指数
1
解决办法
2544
查看次数

标签 统计

ios ×1

ios5 ×1

segue ×1

storyboard ×1

uitableview ×1