-1

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.

Andrew
  • 15,935
  • 28
  • 121
  • 203
  • Add an nslog to each section of code in the .m, and see which ones are called – Jtaylorapps Mar 12 '12 at 03:48
  • I just did this. It called all of the relevant bits, and then i scrolled, and it didn't call anything additional before it's crash. – Andrew Mar 12 '12 at 04:13
  • 1
    possible double-post of [UITableView crashing on scroll](http://stackoverflow.com/questions/9661060/uitableview-crashing-on-scroll) – jscs Mar 12 '12 at 04:18
  • You have to set the delegate and datasource for the tableview – Vidya Murthy Mar 12 '12 at 05:00
  • try changing @interface JEntryTableViewController :UITableViewController { } and connect both data source and delegate to the table view – iOS Developer Mar 12 '12 at 05:54

2 Answers2

1

You way to implement the tableView may not the usual way we often do.

You can add the tableView directly into a ViewController without using another viewController inherit from UITableViewController.

What you should do is identically as what you did in JEntryTableViewController.

When come to the EXC_BAD_ACCESS problem, there are several solutions to find the exact problem. 1. EXC_BAD_ACCESS signal received http://www.touch-code-magazine.com/how-to-debug-exc_bad_access/

  1. at the right section of Xcode break points you can add these kind of break points, it may help you find the exception quickly in your case.
Community
  • 1
  • 1
Henry
  • 481
  • 4
  • 17
0

two things:

  1. write <UITableViewDataSource, UITableViewDelegate> in JEntryTableViewController.h file
  2. write down the crash log here so that we can easily solve your problem.
hchouhan02
  • 948
  • 1
  • 8
  • 18