I'm currently developing a tab bar based application with 5 tabs that have an UITableView each. Each tab is linked to a normal UIViewController, the first two with the ones that xCode creates by default and the others with the ones I created.
If I try to add a table view to the first two view controllers (default ones) everything works smoothly, but when I do the same with the others, the app crashes telling me that:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x4e2f6f0'
and the tableView:numberOfRowsInSection: in my .m file is this (i'm implementing proper delegates in the .h):
I'm currently developing a tab bar based application with 5 tabs that have an UITableView each. Each tab is linked to a normal UIViewController, the first two with the ones that xCode creates by default and the others with the ones I created.
If I try to add a table view to the first two view controllers (default ones) everything works smoothly, but when I do the same with the others, the app crashes telling me that:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x4e2f6f0'
and the tableView:numberOfRowsInSection: in my .m file is this (i'm implementing proper delegates in the .h):
yep, I've declared it and connected it, but usually you don't even have to do this. It looks pretty strange, any other suggestion ?
thanks
How did you setup the tableViews in the first two "default" views? The warning is telling you that UIViewController is receiving an unrecognized selector. This is a tableView method so it would be a fault I believe. If all four viewControllers are just UIViewController's check how the first two implement the tableView you added. Look in their viewDidLoad methods as well to see how the tableView's are loaded.
in the viewDidLoad methods there is nothing in every class as I'm just testing for now. To implement the UITableViews I use the standard methods:
Code:
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
I've used this code in many other UIViewControllers of many projects, I think it's something related to the TabBar which make these new controllers work strange.
in the viewDidLoad methods there is nothing in every class as I'm just testing for now. To implement the UITableViews I use the standard methods:
Code:
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
I've used this code in many other UIViewControllers of many projects, I think it's something related to the TabBar which make these new controllers work strange.
Alright. We'll get this worked out. Did you add the delegate and data source to your .h files for your new viewControllers? Is the entire view a tableView, or is it just a meant to be a small portion of your view?
I'm at work, so I can't step through any codes and duplicate what you have yourself. Let's keep trying to solve this, but I can work it out and follow along later today when I get home...I'm on the east coast of the United States (GMT -0500 hrs) and it is 10:18 AM (1018 hrs) right now. I'll be home around 5:30 PM (1730 hrs) and can get more in depth.
Keep tyring and let me know how it's going in the mean time and I'll come up with more ideas with each post.
It sounds as though you have not declared in your .h what you need to. though with 2 working i would be surprised if you had missed this. Worth a suggestion to discount it anyway:
I know it sounds and is a very simple possible solution, but youd be surprised how often little things like this can crop up when working on too much code or going through it too quickly.
Hope this helps. Ill also keep an eye on this thread and see if i can lend the little bit of wisdom i sometimes manage to come across.
yep I have those delegates in my .h file, I'm sure it's something connected to the tab bar as I often do this kind of process and it always works smoothly
yep I have those delegates in my .h file, I'm sure it's something connected to the tab bar as I often do this kind of process and it always works smoothly
in IB, have you changed the properties in the drop down menu's? I can't remember where they're located right now, but will check in a bit.
also, try adding your tableViews to your viewDidLoad method like this:
Code:
[view addSubview:tableView];
It's this part of the warning
Code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x4e2f6f0'
that causes me to believe it's because your UIViewController is not implementing your tableViews and is treating your tableViews as though they are not there.
if you could, post your .h and .m files for your viewcontroller 3.
Since you're using a UIViewController and not a UITableViewController, you need to add the tableview as a subview. UIViewController does not include those methods. You will have to alloc init the tableView as well. I think that will do the trick.
I might be late , but i think ppl who get this error might take advantage of this answer , anyways the solution is that
"click on the tab bar item in iterface buildder , which you have added (i.e not first two tabs) then go to indentity inspector , change the Class from UITableViewController or watever it would be to your view which you want to show up on this tab" . Thats work for me .
Since you're using a UIViewController and not a UITableViewController, you need to add the tableview as a subview. UIViewController does not include those methods. You will have to alloc init the tableView as well. I think that will do the trick.
sorry for my delay getting back to you.
You only need to add the table view as a subview in code if you don't set it up that way in IB. I almost always hook up the table view to the view controller in IB, so the code you say to add is not needed.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I might be late , but i think ppl who get this error might take advantage of this answer , anyways the solution is that
"click on the tab bar item in iterface buildder , which you have added (i.e not first two tabs) then go to indentity inspector , change the Class from UITableViewController or watever it would be to your view which you want to show up on this tab" . Thats work for me .
Regards
Waqas Ahmed
Makes sense. It sounds like the Apple template expects all the tabs in the tab bar controller to point to UITableViewController objects. They are a special subclass of UIViewController that has table view support built into it. In your case, you are using a generic view controller and adding the delegate and data source methods yourself. That's what I usually do. I don't find the UITableViewController class very useful.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.