1
votes

My iphone program has a Xib view with a tableview dropped in. I've subclassed UITableViewController and am trying to make the UITableView in the xib send it messages. The program crashes when I touch a tableview row.

It properly calls:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}

and the cell.textLabel.text is assigned properly.

Interface snippet:

@interface PlayersDrawsViewController : UIViewController {
    UITableView *uitableView;
    PlayersToDrawTableViewController *pvc;
}
@property (nonatomic, retain) IBOutlet UITableView *uitableView;
@property (nonatomic, retain) IBOutlet PlayersToDrawTableViewController *pvc;

Implementation snippet:

- (void)viewDidLoad
{
    // Setup TableView
    if (pvc == nil) {
        pvc = [[PlayersToDrawTableViewController alloc]
               initWithNibName:@"PlayersToDrawTableViewController" bundle:nil];
        /* works great, loads rows */
        self.uitableView.dataSource = pvc.tableView.dataSource;
        /* EXC_BAD_ACCESS when didSelectRowAtIndexPath is called */
        //self.tableView.delegate = pvc;

    }
}

My UITableViewController Subclass:

@interface PlayersToDrawTableViewController : UITableViewController 
    <UITableViewDelegate>
    {
    }

    @end

How can I get the delegate hooked up so it doesn't crash sending messages?

I've read these threads and either I'm dense or they don't answer my question:

UITableView issue when using separate delegate/dataSource

UITableView superClass for delegate?

Getting “EXC_BAD_ACCESS” when accessing instance variable from within UITableView delegate method

didSelectRowAtIndexPath generates EXC_BAD_ACCESS while willSelectRowAtIndexPath works fine UITableView

1
It might help to post the complete error message. Also, making an instance variable of type UITableViewController as a datasource for another table looks very fishy.Eiko
There's no error message, other than a stack dump. I set a breakpoint in the didSelectRowAtIndexPath method and it gets there. However, the bad access happens at: 0x00fd009b <+0015> mov 0x8(%edx),%edirandomx
also, I'm using Interface Builder to design the Views. I've dropped the UITableView into a UIView. The UITableViewController (pvc) gets data from a sqlite3 source during viewDidLoad. I'm open to suggestion for populating a UITableView as a component of a UIView.randomx
If you are getting EXEC_BAD_ACCESS in didSelectRowAtIndexPath, you should probably add that code here.Deepak Danduprolu
It's doing nothing, just NSLog(@"%s", FUNCTION);randomx

1 Answers

2
votes

If this line is crashing with EXC..:

self.tableView.delegate = pvc;

...did you hook up the tableView reference somewhere? In your code snippet "no" - but maybe you did in the NIB?