1

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

Community
  • 1
  • 1
randomx
  • 2,357
  • 1
  • 21
  • 30
  • 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 Jun 15 '11 at 23:22
  • 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),%edi – randomx Jun 15 '11 at 23:26
  • 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 Jun 15 '11 at 23:30
  • If you are getting `EXEC_BAD_ACCESS` in `didSelectRowAtIndexPath`, you should probably add that code here. – Deepak Danduprolu Jun 15 '11 at 23:47
  • It's doing nothing, just NSLog(@"%s", __FUNCTION__); – randomx Jun 15 '11 at 23:54

1 Answers1

2

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?

Adam
  • 32,900
  • 16
  • 126
  • 153
  • Yes, tried in NIB: Outlet: DataSource -> Players To Draw... Outlet: Delegate -> Players To Draw... Referencing Outlets: view -> Players To Draw... – randomx Jun 16 '11 at 00:01
  • Got it. In NIB, I needed to drag a connection between the Table View Controller Object in the Objects list to the Referencing Outlet in the File's Owner (pvc) connection... in addition to the datasource and delegate connections. It's wired up and works. – randomx Jun 16 '11 at 01:12