views:

54

answers:

2

I am getting the following error on a very simple UITableView:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x5d73210'  

Here is my code:

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 0;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 10;
}
+1  A: 

You have to return at least 1 section... I've tested this in a newly created UIViewController XIB called testes (add new .h and .c files and check the box to created XIB with it and also to make it a UITableViewController subclass) and it works fine.

How did you create the tableview? Did you create it's own XIB like I wrote above or did you just throw a tableview into the MainWindow.xib file? Try creating you own and you should be good. Just make sure in AppDelegate to set the main view that gets added on didFinishLaunchingWithOptions to the new tableview you create. In IB, the UIViewController for the tableview should be set to testes subclass (which is a UITableViewController subclass)

App Delegate files

#import <UIKit/UIKit.h>

@class testes;

@interface testesAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    testes *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet testes *viewController;

@end

and

#import "testesAppDelegate.h"
#import "testes.h"

@implementation testesAppDelegate

@synthesize window;
@synthesize viewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

return YES;
}

And then in the viewcontroller .m file

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
iWasRobbed
+1  A: 

Change 0 to 1

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 10;
}
Aran Mulholland
Repeat answer?? That's not cool.
iWasRobbed
must have done it at roughly the same time...ill give you an upvote. great minds think alike.
Aran Mulholland
I'm still getting the same error even when I return 1
Sheehan Alam