开发者

UITableView Delegate Assignment EXC_BAD_ACCESS

开发者 https://www.devze.com 2023-03-13 12:29 出处:网络
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

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]开发者_StackOverflow社区
               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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消