【发布时间】:2013-09-03 17:14:55
【问题描述】:
我使用 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。 * 首先抛出调用栈: (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:终止调用抛出异常
这是 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
怎么了?!
谢谢。
【问题讨论】:
-
你是从单个原型单元格还是从 tableView 本身?
-
我正在从单个表格单元格中分离
-
如果您 Ctrl+单击从原型单元格到下一个 VC 并创建了一个 segue(推送或模态),那么您应该不会遇到该错误。
-
@CaptJak - 现在已修复。错误地,我正在使用的 ViewController 被创建为 TableViewController。感谢您的帮助。
标签: ios objective-c uistoryboard