views:

26

answers:

2

Hi everyone,

I am building an app that uses a TabBarController to display several other views. In one of these views, I'm using a navigation controller to navigate some tabular data. When the user click's this tab, I load in the NavigationController which in turn loads the TableView that I'm using. The issue is that I get the following error upon load of the TableView Controller:

-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6b37b10

I have read everywhere that this type of error usually comes from a misconnection in IB or that a class is not correct in the view controller. Here is my code and screenshots of IB as to help debug this for me.

Thanks in advance!

The Error I'm Receiving

alt text The TableView's Connections in IB

alt text The File Owner's Class alt text My Interface File

@interface FAQListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {

    // Dictionary that will hold the FAQ Key/Values
    NSMutableArray  *arrFAQData;

}

Implementation

@implementation FAQListViewController

// Implementation for UITableView numberOfRowsInSection protocol
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [arrFAQData count];

}

// Implementation for UITableView cellForRowAtIndexPath protocol
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // See if we have any cells available for reuse
    UITableViewCell *objCell = [tableView dequeueReusableCellWithIdentifier:@"FAQCell"];
    if (objCell == nil) {

        // No reusable cell exists, so let's create a new one
        objCell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: @"FAQCell"];

    }

    // Give it data
    NSDictionary *objRow = [arrFAQData objectAtIndex: [indexPath row]];
    objCell.textLabel.text = [objRow valueForKey:@"Title"];

    // Return the created cell
    return objCell;


}

// Selection Event Handler
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Get the value for the selected key
    NSDictionary *dictRow = [arrFAQData objectAtIndex:[indexPath row]];
    NSString *strURL = [dictRow valueForKey: @"URL"];

    // Alert result
    UIAlertView *objAlert;
    objAlert = [[UIAlertView alloc] initWithTitle:@"Alert" message: strURL delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 

    // Release created objects
    [objAlert show];
    [objAlert release];

    // Deselect row
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}
- (void)viewDidLoad {

    // Pull in FAQ from Plist
    NSString *strFAQPlist = [[NSBundle mainBundle] pathForResource:@"FAQData" ofType:@"plist"];
    arrFAQData = [[NSMutableArray alloc] initWithContentsOfFile: strFAQPlist];


    [super viewDidLoad];
}

- (void)dealloc {

    [arrFAQData release];


    [super dealloc];
}
A: 

Try to make the Delegate & Datasource connections programmatically. I had a similar issue were an optional method of the UITableViewDelegate protocol was not being called for no apparent reason (while other delegate methods were working as expected) unless I made the connection programmatically. Since the method was optional, however, no exception was thrown.

Toastor
+1  A: 

First of all, this is a well-constructed question, I wish everyone posted screen shots and full source code. :-)

It looks like the message is being sent to a generic UIViewController, instead of FAQListViewController. This tells me that perhaps when you instantiate the FAQListViewController, you are creating an instance of UIViewController instead?

To instantiate the FAQ list, you should be using something like:

[[FAQListViewController alloc] initWithNibName: @"FAQViewController" bundle: nil];

Your error might arise if you were instead instantiating it like:

[[UIViewController alloc] initWithNibName: @"FAQViewController" bundle: nil];

Chris Garrett
Thank you for that. Helped a lot!
Jesse Bunch