麻烦通过segue传递信息

时间:2013-10-03 01:11:55

标签: objective-c

好的。我无法通过segue从一个UITableViewController传递数据到另一个UITableViewController。正确的信息无法加载。如果没有一堆关于设置的无休止的讨论,请点击:

在上面(传递)viewController方面:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"deriv"]) {
    NSIndexPath *indexPath = [self.tableView2 indexPathForSelectedRow];
    DerivationController *destViewController = segue.destinationViewController;
    destViewController.derivationName = [equationsList2 objectAtIndex:indexPath.row];
}

在接收viewController方面:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"derivCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

cell.textLabel.text = [derivations objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [details objectAtIndex:indexPath.row];
return cell;
}
  • equationsList2是NSArray实例中的方程列表。根据选择的是哪一个,可以从NSArrays“derivations”和“details”相应地设置cell.textLabel和cell.detailTextLabel。

  • DerivationController.h的声明在传递viewController的标题列表中。

  • 不会引发任何错误。

有什么想法吗?

设置'派生'和'详细'的代码:

if ([_derivationName isEqualToString:@"Momentum-Velocity"])
{
    // Equation 1:
    derivations = [NSArray arrayWithObjects:
                   @"Momentum",
                   @"Mass",
                   @"Velocity",
                   nil];
    details = [NSArray arrayWithObjects:
               @"Momentum units in kg ∙ m/s",
               @"Mass units in kilograms (kg)",
               @"Velocity units in meters/second (m/s)",
               nil];

0 个答案:

没有答案
相关问题