0

I'm pretty new to this, but when I try to simulate on the iOS simulator it stops and then this error pops up...I added a View Controller for my a table view in my storyboard. I will include the file so you guys have enough info to help me out.

Im just trying to get my table view to display some elements of an array. A navigation controller is the root view controller and it goes right into the table view controller where I want to display the array courses.

Here is my app deligate

//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;
}

Here is my 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;
}

Here is my coursesviewcontroller.h

#import <UIKit/UIKit.h>

@interface CoursesViewController : UITableViewController
@property (nonatomic, strong) NSMutableArray *courses;

@end

Here is my courses.m and courses.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

When I try to run in the simulator, it flips to the main.m file and displays the SIGARBT error on thread 1.

If I havent included enough info let me know and ill post more.

CONSOLE OUTPUT:

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) 
drfear
  • 121
  • 1
  • 7
  • 1
    what is the output on the console in Xcode? – sergio Oct 04 '12 at 16:07
  • 2012-10-04 12:33:15.917 MacMarks[270:c07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]' *** First throw call stack: (0x1c8e012 0x10cbe7e 0x1c43b44 0x2502 0x107b7 0x10da7 0x11fab 0x23315 0x2424b 0x15cf8 0x1be9df9 0x1be9ad0 0x1c03bf5 0x1c03962 0x1c34bb6 0x1c33f44 0x1c33e1b 0x117da 0x1365c 0x22fd 0x2225) libc++abi.dylib: terminate called throwing an exception (lldb) – drfear Oct 04 '12 at 16:40
  • Ah that helps me a little, I'd still like to hear what you think :) – drfear Oct 04 '12 at 16:41
  • check you courses array, if it contains any objects before sending to your CourseViewController – Bartu Oct 04 '12 at 16:51

2 Answers2

0

Since you're using a storyboard, you don't do anything in code to instantiate the navigation controller or your CoursesViewController (everything you posted other than the "return yes" should be deleted). To get the array into your CoursesViewController, add the following code to its viewDidLoad method:

    self.courses = [NSMutableArray arrayWithCapacity:20];
    Courses *course = [[Courses alloc] init];
    course.code = @"SFWR 3X03";
    course.units = 3;
    [courses addObject:course];
    [super viewDidLoad];
    [self.tableView reloadData];

I'm assuming that you have a property called courses (typed strong) in your .h file.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Im getting errors for navigationController not found on object NavigationController now...I updated my output from earlier if that helps...It may be an issue with my storyboard... – drfear Oct 04 '12 at 18:51
  • Ok, I didn't notice that you were using storyboards. What is in your storyboard and how did you get it/them there? – rdelmar Oct 04 '12 at 19:29
  • Okay, so I have a navigation controller which automatically pushes a table view controller and the table view controller is what I am trying to get to display this array. The table view controller is attached to other things but I'm just trying to figure out this view first lol – drfear Oct 04 '12 at 21:38
  • I also might want to add that everything was working before I added courses view controller. But obviously I need it or I can do anything with my table view. And the courses view controller is of subclass NSTableViewController – drfear Oct 04 '12 at 21:46
  • See my edited answer -- it's much easier than you're making it when you use storyboards. – rdelmar Oct 04 '12 at 22:31
0

Reading the comments, it's a little difficult to tell what problem you're trying to solve but this error...

'-[UITableViewController loadView] loaded the     
"fBI-R0-7j9-view-iYf-OA-4cJ" nib but didn't get a UITableView.'

...is saying that the object connected to the view outlet in your table view controller is something other than a UITableView or a subclass of UITableView. Look at that controller in your storyboard and check what view linked to.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57