1

更新

DetailViewController *wordDetail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
wordDetail.wordWordString = [[NSString alloc] initWithString:[[myArray objectAtIndex:indexPath.row] objectForKey:@"word"]];
wordDetail.wordDefinitionString = [[NSString alloc] initWithString:[[myArray objectAtIndex:indexPath.row] objectForKey:@"definition"]];
wordDetail.title = [[myArray objectAtIndex:indexPath.row] objectForKey:@"name"];

[self performSegueWithIdentifier:@"showDetail" sender:self];

这是我为 segue 做的新准备(你的意思是如果我使用上述方法,我就不再需要它了,还是根本不需要?我现在确定我的所有标识符是否都在排队......你觉得呢?

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
if ([[showDetail] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];

图它也可能有助于查看我的 DetailViewController.m ......

-(void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
    _detailItem = newDetailItem;

    // Update the view.
    [self configureView];
}

if (self.masterPopoverController != nil) {
    [self.masterPopoverController dismissPopoverAnimated:YES];
}        
}

-(void)configureView
{
//Update the user interface for the detail item.

if (self.detailItem) {
    self.detailDescriptionLabel.text = [self.detailItem description];
}
}


- (void)viewDidLoad
{
    wordWordLabel.text = wordWordString;
    wordDefinitionLabel.text = wordDefinitionString;

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self configureView];
}
4

1 回答 1

1

您的第一部分代码很好。然而,它正在创建一个 DetailViewController 然后推动它。这意味着永远不会有 Segue,因此您的第二个代码根本不重要。您需要决定要使用哪个。

[self.navigationController pushViewController:wordDetail animated:YES];

此行将 viewController 推入堆栈。或者

[self performSegueWithIdentifier:@"showDetail sender:self];

将在 Storyboard 中使用名为 showDetail 的 segue。你不能两者兼得,你需要选择。

故事板标识符 故事板标识符

于 2013-03-01T18:24:28.480 回答