0

在做了一些教程之后,我正在尝试制作我的第一个 iOS 应用程序。我正在制作一个简单的标题/新闻阅读器,它从 ESPN API 将新奥尔良圣徒队的标题和故事作为 json 提取,在表格视图中显示标题,然后在用户点击标题时在详细视图中显示故事的文本.

该应用程序编译并运行,没有错误或警告。prepareForSegue 方法在用户点击顶部表格视图中的标题时执行。我可以在调试器中逐步执行此代码。如果我单步执行 prepareForSegue 方法,它会调用 detailViewController 的 setStory 方法,该方法又会调用 configureview 方法。但随后它带我进入 main.m,应用程序关闭,没有显示详细视图。

我是菜鸟。我错过了什么?为什么我看不到详细视图?也许我需要一个 IBAction 来加载 IBOutlet?

SaintsMasterViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        saintsDetailViewController *detailViewController = [segue destinationViewController];
        saintsNewsStory* displayThisStory =[self.dataController objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];
        [detailViewController setStory:displayThisStory];
    }
}

SaintsDetailViewController.m

- (void)setStory:(saintsNewsStory *)newStory
{
 //   if (_story != newStory) {
        _story = newStory;
        // Update the view.
     //   [self configureView];
  //  }
}


- (void)configureView
{
    self.storyText.text = self.story.storyText;
}

- (void)viewDidLoad     //the app never gets here. if i put a breakpoint here it never gets here
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self configureView];
}

saintsDetailViewController.h

@class saintsNewsStory;
@interface saintsDetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextView *storyText;
@property (retain, nonatomic) saintsNewsStory *story;
@end

控制台显示此错误:

SaintsHeadlineReader[9608:11303] * 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键 detailDescriptionLabel 的键值编码。” * First throw call stack: (0x1c90012 0x10cde7e 0x1d18fb1 0xb7a711 0xafbec8 0xafb9b7 0xb26428 0x2320cc 0x10e1663 0x1c8b45a 0x230bcf 0xf5e37 0xf6418 0xf6648 0xf6882 0x102235 0x3013d2 0xff4f3 0xff777 0xff7b7 0x46afe2 0x45cad9 0x45cb54 0xc4899 0xc4b3d 0xacbe83 0x1c4f376 0x1c4ee06 0x1c36a82 0x1c35f44 0x1c35e1b 0x1bea7e3 0x1bea668 0x1565c 0x204d 0x1f75 0x1) libc++abi. dylib:终止调用抛出异常

似乎 textview 有一个详细标签,也许我需要一个出口?

4

2 回答 2

0

测试我的理论。在您当前使用的行之前或之后立即放入NSLog(@"%d", [self.yourTableView indexPathForSelectedRow].row);您当前的方法,并查看它在您的控制台中返回的内容。大概是0。prepareForSegueindexPathForSelectedRow

不要将 UITableViewCell Prototype 的 segue 连接到 DetailViewController,而是将其从 UITableViewController 连接到 DetailViewController,然后使用以下方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SaintsDetailViewController *detailViewController = [[SaintsDetailViewController alloc] init];
    saintsNewsStory* displayThisStory =[self.dataController objectAtIndex:indexPath.row];
    [detailViewController setStory:displayThisStory];
    [self performSegueWithIdentifier:@"showDetail" sender:indexPath];
}

和你的prepareForSegue:方法:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        saintsDetailViewController *detailViewController = [segue destinationViewController];
    }
}
于 2012-10-23T23:39:25.670 回答
0

更改此行:

saintsDetailViewController *detailViewController = [segue destinationViewController];

对此:

saintsDetailViewController *detailViewController = (saintsDetailViewController *)[segue destinationViewController];

编辑:您应该首先显示您的视图,然后调用该configureView方法。尝试调用configureViewviewDidLoadViewController。

- (void)setStory:(saintsNewsStory *)newStory
{
 //   if (_story != newStory) {
        _story = newStory;
        // Update the view.
       // [self configureView];
  //  }
}


-(void) viewDidLoad {
      [self configureView];
}


- (void)configureView
{
    self.storyText.text = self.story.storyText; //the app gets to here but does not show the view. why?
}
于 2012-10-23T23:22:22.017 回答