This code copied anywhere else seems to work. It's just inside my app where it crashes. Any ideas why?
another .m...
#import "JEntryTableViewController.h"
@interface JCreateViewController () {
JEntryTableViewController *_tableView;
}
@property (nonatomic, strong) JEntryTableViewController *tableView;
@end
@implementation JCreateViewController
@synthesize tableView = _tableView;
- (id)init
{
self = [super init];
if (self) {
self.tableView = [[JEntryTableViewController alloc] initWithStyle:UITableViewStylePlain];
[self.view addSubview:self.tableView.view];
}
return self;
}
JEntryTableViewController.h:
#import <UIKit/UIKit.h>
@interface JEntryTableViewController : UITableViewController {
}
@end
JEntryTableViewController.m:
#import "JEntryTableViewController.h"
@interface JEntryTableViewController ()
@end
@implementation JEntryTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CountryCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60;
}
@end
I ran this as a quick test to make sure it was set up right, and to my surprise, when i scroll back to a cell I've already seen, it crashes and gives me a EXC_BAD_ACCESS error. Unfortunately the debugging area isn't giving me anything back that I can work with, and i really don't know what the problem is - it's such a basic, simple bunch of code. I don't know what to fix. It should work.