0

我使用 Storyboards 制作了一个非常简单的应用程序(第一次)。

该应用程序基本上是一个嵌入在导航控制器中的表视图控制器,并与显示图像的视图控制器相连接。但是当我点击一行时,它给了我一个 Thread 1 SIGABRT 错误。这是日志:

2013-09-03 22:37:16.669 FootballPlayers[7226:c07] * 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UITableViewController loadView] 加载了“PcV-xW-t12-view-xx8-ac- 4rU" nib 但没有获得 UITableView。* First throw call stack: (0x1c94012 0x10d1e7e 0x1c93deb 0x245357 0xf6ff8 0xf7232 0xf74da 0x10e8e5 0x10e9cb 0x10ec76 0x10ed71 0x10f89b 0x10fe93 0xc4823f7 0x10fa88 0x46be63 0x45db99 0x45dc14 0xc5249 0xc54ed 0xacf5b3 0x1c53376 0x1c52e06 0x1c3aa82 0x1c39f44 0x1c39e1b 0x1bee7e3 0x1bee668 0x15ffc 0x226d 0x2195 0x1) libc++abi.dylib: terminate called throwing一个例外

这是 TableViewController 的实现

#import "PlayersTableViewController.h"

@interface PlayersTableViewController ()

@end

@implementation PlayersTableViewController

NSMutableArray *players;

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    DisplayViewController *dvc = [segue destinationViewController];
    NSIndexPath *path = [[self tableView] indexPathForSelectedRow];
    [dvc setCurrentPlayer:[players objectAtIndex:[path row]]];

}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    players = [[NSMutableArray alloc] init];

    Player *stevenGerrard = [[Player alloc] init];
    [stevenGerrard setName:@"Steven Gerrard"];
    [stevenGerrard setFileName:@"Steven Gerrard.jpg"];
    [stevenGerrard setInformation:@"International Team : England, Club : Liverpool FC"];
    [players addObject:stevenGerrard];

    Player *cristianoRonaldo = [[Player alloc] init];
    [cristianoRonaldo setName:@"Cristiano Ronaldo"];
    [cristianoRonaldo setFileName:@"Cristiano Ronaldo.jpg"];
    [cristianoRonaldo setInformation:@"International Team : Portugal, Club : Real Madrid"];
    [players addObject:cristianoRonaldo];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [players count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"PlayerCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    Player *current = [players objectAtIndex:[indexPath row]];
    [[cell textLabel] setText:[current name]];

    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}

@end

怎么了 ?!

谢谢你。

4

3 回答 3

1

一件非常方便的事情是添加一个异常断点https ://developer.apple.com/library/ios/recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html

这样,您可能会在代码中看到出错的确切位置。

如果在点击一行后出现错误,目标视图控制器的代码也很有趣。

于 2013-09-03T17:35:30.053 回答
0

您的 nib 文件很可能构造不正确。

看起来除了连接到表视图控制器出口的表视图之外,您还有其他东西应该指向表视图。

于 2013-09-03T17:19:45.190 回答
0

确保在 .h 文件中继承 UITableViewController 而不是 UIViewController (或其他任何东西)。

所以它应该看起来像:

@interface PlayersTableViewController : UITableViewController
于 2013-09-04T02:35:48.060 回答