views:

493

answers:

3

Hi. I have a problem with my application for the iPhone.

It's a tab based application. In one of the tabs, I have a Table View. I have set it up to load in data from a PLIST.

My problem is that when I try to build and run it, the application either crashes, or stays at a black screen with the error message "Terminating app due to uncaught exception".

I looked in the console, and found that the error probably laid in this string:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return workouts.count;
}

(error message:)

2010-02-06 21:50:54.733 Mudo[52439:207] *** -[FirstViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x39101a0
2010-02-06 21:50:54.735 Mudo[52439:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[FirstViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x39101a0'
2010-02-06 21:50:54.736 Mudo[52439:207] Stack: (
    29344859,
    2569487625,
    29726779,
    29296246,
    29148866,
    4413562,
    4420938,
    4419935,
    3136474,
    3076985,
    3118420,
    3106975,
    55857840,
    55857263,
    55855302,
    55854394,
    2780921,
    2804616,
    2787027,
    2814133,
    37441233,
    29129600,
    29125704,
    2780777,
    2818051
)

Building the app does not generate any errors.

Please help me? Thanks :)

+1  A: 

If you look at the actual text of the exception, 'NSInvalidArgumentException', reason: '*** -[FirstViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x39101a0', you can see the root of the problem. Somewhere in your code you're calling tableView:numberOfRowsInSection: on a FirstViewController, which doesn't implement that method.

Exceptions are not caught at compile-time, but rather thrown at runtime. You may want to read up on them if you aren't familiar, as they're a fairly important part of many programming languages.

http://en.wikipedia.org/wiki/Exception_handling

Ian Henry
How do I implement that, in that case, then?
Emil
Wait a minute,I don't have any code in my FirstViewController-file.. Could that have anything to do with it?
Emil
Of course it has something to do with that. If you've set FirstViewController to be the table's datasource/delegate then it needs to implement the methods from those protocols!
Jasarien
Yep. The solution is either to implement the method, or to not call it in the first place. If it's being called by mistake, (ie you have another view controller that is a `UITableViewController`) then don't call it. If that's supposed to be the controller, though, you'll have to implement the necessary methods. http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html
Ian Henry
I'm pretty confused about this..The file my current code is in is FirstView.h/m.The file that my interface for that tab is FirstView.xib.The file the TableView wants to get loaded from is FirstViewController.h/m.In interface builder, I hooked up the dataSource and delegate to "File's Owner".I don't understand why it wants to be shown from the FirstViewController.h/m file..? Could deleting that file fix it? I don't really need it...
Emil
Crap. Deleting them does definetely not fix the problem :/
Emil
A: 

I'm guessing, since FirstViewController is one of the standard example classes created when starting a new Tab Bar based application in Xcode that you haven't changed its super class or implemented the methods of UITabeViewDelegate and UITableViewDataSource.

Either that or you've implemented the methods from those protocols in another class, but set FirstViewController as the table view's delegate/datasource.

We need more information to know for sure.

Jasarien
Hm, you're right.. I obviously set the TableView's delegate and datasource to FirstViewController.. How do I change this..?Thanks :)
Emil
A: 

I fixed it :)

I added implementation for both FirstView and FirstViewController in the FirstView.h/m file, and deleted the FirstViewController.h/m file.

But now I have another problem...

My interface now only shows the table view.. My interface is supposed to look like this:

http://files.droplr.com/files/14763142/lZg1Q.Skjermbilde%202010-02-06%20kl.%2023.00.39.png

But looks like this: (I'll post the link in a comment, because I obviously am not allowed to post two links -.-)

Can anyone help me based on these pictures? Thanks :)

Emil
http://files.droplr.com/files/14763142/lZjaB.Skjermbilde%202010-02-06%20kl.%2023.02.37.png
Emil
This should be posted as a separate question, as it is a separate question. No one will see it if it's hiding as an answer here.
Ian Henry