Ali
Ali

Reputation: 9994

Custom TableView and using didSelectRowAtIndexPath in iOS

I have created a custom TableView by following this Custom UITableViewCell

I creared a CustomerCell and then use it like this in ViewController:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *uniqueIdentifier = @"cutomerCell";

    CustomerCell *cell = nil;
    cell = (CustomerCell *) [self.tableview dequeueReusableCellWithIdentifier:uniqueIdentifier];

    Customer *customer = [self.customers objectAtIndex:[indexPath row]];
    if(!cell)
    {
        NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"CustomerCell" owner:nil options:nil];
        for(id currentObject in topLevelObject)
        {
            if([currentObject isKindOfClass:[CustomerCell class]])
            {
                cell = (CustomerCell *) currentObject;
                break;
            }
        }
    }
    cell.nameLabel.text = customer.name;

    return cell;
}

Everything works fine. But then I start the next link UINavigationController

The problem is when I use this method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@ "hi");   
}

When I click on an item in TableView, nothing happen. It could be because of I implement the Custom TableView and then I can't use didSelectRowAtIndexPath method, but how can I fix it?

Upvotes: 0

Views: 886

Answers (3)

Tripti Kumar
Tripti Kumar

Reputation: 1581

The error you are getting is related to your nib and not your UITableView. You should check if the view of Customer Detail class is connected to its owner in the nib. That is why it crashes as soon as you try to use

[self.navigationController pushViewController:self.customerDetail animated:YES];

Upvotes: 1

user529758
user529758

Reputation:

Subclassing the table view should not cause such a problem -- a subclass, by definition, does everyting plus something more than that of its superclass. It seems that you have only set the data source but the delegate:

tableView.delegate = self;

Upvotes: 0

Nicolai
Nicolai

Reputation: 328

Did you set the delegate? tableView.delegate = self; and you should be fine, I guess.

Upvotes: 0

Related Questions