好吧。我无法通过 segue 从一个 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];
}
在接收视图控制器端:
- (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 实例中的方程式列表。根据选择哪一个,cell.textLabel 和 cell.detailTextLabel 会根据 NSArrays “派生”和“详细信息”进行相应设置。
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];