Wayne Mcfayden
Wayne Mcfayden

Reputation: 55

Table view crashing app

I'm trying my hand at iphone programing. I have been following this tutorial however it doesn't seem to be working for me. i use this tutorial link

I have checked the code several times and seems to be correct but when I run the app and push the tableview the app crashes. No errors or warnings. Any help would be appreciated. Here is the code.

@implementation SimpleTableViewController
{
NSArray *tableData;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize table data
tableData = [NSArray arrayWithObjects:@"one", @"Two", @"Three", @"Four", @"five",      nil];
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section
{
return [tableData count];
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
} 

I'm receiving EXC_BAD_ACCESS

Here is the backtrace (gdb) backtrace

#0  0x00efe5a8 in objc_exception_throw ()
#1  0x00d62628 in +[NSException raise:format:arguments:] ()
#2  0x00d6259a in +[NSException raise:format:] ()
#3  0x00362b75 in -[UIViewController _loadViewFromNibNamed:bundle:] ()
#4  0x00360709 in -[UIViewController loadView] ()
#5  0x003605e3 in -[UIViewController view] ()
#6  0x0035ea57 in -[UIViewController contentScrollView] ()
#7  0x0036f201 in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] ()
#8  0x0036d831 in -[UINavigationController _layoutViewController:] ()
#9  0x0036eb4c in -[UINavigationController _startTransition:fromViewController:toViewController:] ()
#10 0x00369606 in -[UINavigationController _startDeferredTransitionIfNeeded] ()
#11 0x0037083e in -[UINavigationController pushViewController:transition:forceImmediate:] ()
#12 0x003694a0 in -[UINavigationController pushViewController:animated:] ()
#13 0x000022cf in -[PocketHusbandViewController displayCarView:] (self=0x4e12870, _cmd=0x31d2, sender=0x4e16f30) at /Users/wayne/Desktop/programming/Pocket Husband/Classes/PocketHusbandViewController.m:21
#14 0x002b2a6e in -[UIApplication sendAction:to:from:forEvent:] ()
#15 0x003411b5 in -[UIControl sendAction:to:forEvent:] ()
#16 0x00343647 in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#17 0x003421f4 in -[UIControl touchesEnded:withEvent:] ()
#18 0x002d70d1 in -[UIWindow _sendTouchesForEvent:] ()
#19 0x002b837a in -[UIApplication sendEvent:] ()
#20 0x002bd732 in _UIApplicationHandleEvent ()
#21 0x016dfa36 in PurpleEventCallback ()
#22 0x00d8b064 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#23 0x00ceb6f7 in __CFRunLoopDoSource1 ()
#24 0x00ce8983 in __CFRunLoopRun ()
#25 0x00ce8240 in CFRunLoopRunSpecific ()
#26 0x00ce8161 in CFRunLoopRunInMode ()
#27 0x016de268 in GSEventRunModal ()
#28 0x016de32d in GSEventRun ()
#29 0x002c142e in UIApplicationMain ()
#30 0x00001e90 in main (argc=1, argv=0xbfffefd4) at /Users/wayne/Desktop/programming/

I think the problem might be here when I call the view;

-(IBAction)displayView:(id)sender {
carMainViewController *carViewController = [[carMainViewController alloc]initWithNibName:@"carMainViewController" bundle:[NSBundle mainBundle]];
[carViewController.navigationItem setTitle:@"Cars"];
[self.navigationController pushViewController:carViewController animated:YES];
[carViewController release];

}

Any thoughts?

Upvotes: 1

Views: 156

Answers (2)

Darshan Kunjadiya
Darshan Kunjadiya

Reputation: 3329

Retain your array like this code:

 tableData = [NSArray arrayWithObjects:@"one", @"Two", @"Three", @"Four", @"five",      nil];
[tableData retain];

i hope this code useful for you.

Upvotes: 1

Codinfox
Codinfox

Reputation: 608

Your code works perfectly for me.

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

This is not a required protocol method, but it is usually there to make the app functions properly. Certainly, it is ok to omit this method.

Maybe you should check if your class has conformed to UITableViewDataSource and UITableViewDelegate. Then check if your tableview in IB has set its datasource and delegate to the file owner.

enter image description here

EDIT:

You can add an exception breakpoint from the breakpoint navigator to find the exact place where the exception was thrown. And please give some more detailed error log.

enter image description here

Upvotes: 0

Related Questions