我对此很陌生,但是当我尝试在 iOS 模拟器上进行模拟时,它会停止,然后弹出此错误……我在情节提要中为我的表格视图添加了一个视图控制器。我将包含该文件,以便你们有足够的信息来帮助我。
我只是想让我的表格视图显示数组的一些元素。导航控制器是根视图控制器,它直接进入我要显示数组课程的表视图控制器。
这是我的应用程序
//AppDeligate.m
#import "AppDelegate.h"
#import "CoursesViewController.h"
#import "Courses.h"
@implementation AppDelegate{
NSMutableArray *courses;}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions
(NSDictionary *)launchOptions
{
courses = [NSMutableArray arrayWithCapacity:20];
Courses *course = [[Courses alloc] init];
course.code = @"SFWR 3X03";
course.units = 3;
[courses addObject:course];
UINavigationController *navigationController =
(UINavigationController *)self.window.rootViewController;
CoursesViewController *CoursesViewController =
[[navigationController viewControllers] objectAtIndex:1];
CoursesViewController.courses = courses;
return YES;
}
这是我的 CoursesViewController.m
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [self.courses count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"PlayerCell"];
Courses *course = [self.courses objectAtIndex:indexPath.row];
cell.textLabel.text = course.code;
return cell;
}
这是我的课程viewcontroller.h
#import <UIKit/UIKit.h>
@interface CoursesViewController : UITableViewController
@property (nonatomic, strong) NSMutableArray *courses;
@end
这是我的课程.m 和课程.h
#import "Courses.h"
@implementation Courses
@synthesize code;
@synthesize units;
.
#import <Foundation/Foundation.h>
@interface Courses : NSObject
@property (nonatomic, copy) NSString *code;
@property (nonatomic, assign) int units;
@end
@end
当我尝试在模拟器中运行时,它会翻转到 main.m 文件并在线程 1 上显示 SIGARBT 错误。
如果我没有包含足够的信息,请告诉我并发布更多信息。
控制台输出:
2012-10-04 14:44:14.726 MacMarks[475:c07] *** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the
"fBI-R0-7j9-view-iYf-OA-4cJ" nib but didn't get a UITableView.'
*** First throw call stack:
(0x1c8e012 0x10cbe7e 0x1c8ddeb 0x242417 0xf4648 0xf4882 0xf4b2a 0x10bef5 0x10bfdb 0x10c286
0x10c381 0x10ceab 0x10cfc9 0x10d055 0x2123ab 0x6392d 0x10df6b0 0x228afc0 0x227f33c
0x228aeaf 0x1028cd 0x4b1a6 0x49cbf 0x49bd9 0x48e34 0x48c6e 0x49a29 0x4c922 0xf6fec 0x43bc4
0x43dbf 0x43f55 0x4cf67 0x10fcc 0x11fab 0x23315 0x2424b 0x15cf8 0x1be9df9 0x1be9ad0
0x1c03bf5 0x1c03962 0x1c34bb6 0x1c33f44 0x1c33e1b 0x117da 0x1365c 0x22fd 0x2225)
libc++abi.dylib: terminate called throwing an exception
(lldb)