UITableView in each tab - iphone

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:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
do you now any solution ? I've looked around with no result
thanks in advance for answers

Check those two things.
1) if your other viewControllers are subclasses of UIViewController then they should implement the delegate methods:UITableViewDelegate and UITableViewDataSource. Meaning it is not only required to implement them in your code but to tell the compiler that you will.
#interface thirdViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
2) or try to see if your viewController is of type UITableViewController.
#interface thirdViewController : UITableViewController

Related

I can't Segue using a UIButton from UIViewController to UITableViewController

I'm getting Thread 1 SIGABRT in my AppDelegate class with the following
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController
loadView] instantiated view controller with identifier
"UIViewController-ynt-fo-t3z" from storyboard "Main", but didn't get a
UITableView.'
Storyboard arrangement:
UIViewController --> UITableViewController
I'm using a menu Button item from UIViewcontroller to trigger the segue. I have tried everything including preparedforSegue method. The only way around is to change the target view controller back to UIViewController while implementing UITableViewDelegate and UITableViewDataSource which I'm not too fond of using. Any solutions to my madness?
I had a similar issue long time ago; I tried anything, and nothing worked. I ended up using a new UITableViewController and segueing to it; And the issue was resolved. (it seemed like a bug in Xcode or something)
Do the same and see if it works for you.

Reload and display a tableView whitch is based on a view in the MainStoryboard

I'm searching for a solution for the upper since last week, but I found no solution on the internet. So I thought I'll get help here.
Now to may question: I have a MainStoryboard and in it a ViewController with a View. On that view I've put a tableView.
ViewController.h
IBOutlet UITableView *tableView
//on bottom
#property (nonatomic, retain) UITableView *tableView;
ViewController.m I've synthesized it and now I would like to reload and display it while the view is shown.
The following things I tested with no result: [tableView reloadData]; [self.tableView reloadData]; [self.tableView setNeedsDisplay];
And if I used [self.view setNeedsDisplay]; I've got the following Error:
Terminating app due to uncaught exception 'NSInternatlInconsistencyExeption', reason: 'Could not load NIB in bundle: 'NSBundle <...> (loaded)' with name 'ViewController'' * First thow call stack: (...) terminate called throwing an exception(lldb)
Thats right, there is no NIB file, because I've used the Storyboard. Well have anyone an idea?
Only thing I've found is, that if I reload the view by a button on the view within the Storyboard, the tableView gets reloaded - complete reload - but that is no solution.
Can I do something for that in -(void)prepareForSegue:(UIStoryboard *)segue sender:(id)sender? That method I'm using only for an popover till now.
Have you actually connected the IBOutlet up in Interface Builder?
Xcode should tell you if it's connected: it'll show a little circle in the margin of your header file, and if that circle has a dot inside it it's connected, if not then it isn't.
To connect an outlet in Interface Builder, right-drag from the thing with the outlet (i.e. your view controller) to the thing you want to connect it to (your table), and when you let go it gives you a menu of possible outlets to choose from.

programmatically create UITableViewController IOS 5

When starting a new project (single view based), I began to get a strange crash when attempting to use a custom UITableViewController. The custom UITableViewController works just fine in other application started a while back, but now it seems to fail when used in new projects.
This is how I am instantiating the UITableViewController:
TestViewController * tableViewController = [[TestViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.view addSubview:tableViewController.tableView];
The compiler is a lot more strict now, so I make sure to add the required protocols in the headers as follows:
#interface TestViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
I get the following message:
-[__NSMallocBlock__ numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x654dcd0
In the implementation for the custom UITableViewController, I am hard coding the number of section and rows, but I am still getting this problem.
I don't know where to go from here, I appreciate any help I can get,
Thanks

iPad application UITableView delegate methods are not getting called

I am using the same technique as i populate my UITableView in iphone while writing my iPad application.
Tab Bar Controller >UINavigationController>UITableViewController of type myCustomTable(load From NIB)
MyCustomTableViewController NIB and class file implements the delegate methods
#interface MyCustomTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
NSMutableArray *PDFList;
IBOutlet UITableView *PDFTable;
}
but my delegate methods are not getting called. What do i do?
Found the solution....
in the tableView delegate method
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
i was returning 0 and hence none of the delegate methods were being called.
Did you set the delegate and datasource of the table in IB? If you have, and everything is wired up, it should work.
FWIW - This is my biggest problem with nibs. If you run into problems it's much harder to ask for help from people who aren't local.
Make sure you have properly set your 'Class' in Identity Inspector (Tools -> Identity Inspector) in Interface Builder. Also set the appropriate 'Referencing Outlet' in Interface Builder.

Problem with loading UITableView in Navigation-based App [duplicate]

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
In Navigation-based App, when i try to load another view which has got implemented UITableView using initWithNibName:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *detailsViewController = [[UIViewController alloc] initWithNibName:#"bloop2ViewController" bundle:nil];
[[self navigationController] pushViewController:detailsViewController animated:YES];
[detailsViewController release];
}
after clicking UITableView cell i get:
2009-06-13 11:44:41.089 Bloop[75227:20b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0xd446f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
2009-06-13 11:44:41.092 Bloop[75227:20b] Stack: (
807902715, 2429103675, 808061681, 810717848, 810716389, 816538544, 807805711, 816533170, 816541363, 815230552, 815224116, 815223834, 815217291, 815258907, 815254969, 815262662, 815243017, 815265053, 815242666, 11044, 815018240, 815005661, 810768858, 807687328, 807683624, 839142449, 839142646, 814752238, 9088, 8942
)
But when i disconnect UITableView in InterfaceBuilder, view is loaded without any problems (except there's no way to push data into it).
UITableView implementation is proper - i tried it in a fresh XCode project, and it worked just fine.
The error message says you are trying to set the property "tableView" on an object of type UIViewController, which it does not have. I am just guessing, but maybe you have a derived view controller in your nib file, that has the property tableView, but then you construct not your derived object, but a UIViewController. You should try:
MyTableViewController *detailsViewController = [[MyTableViewController alloc] initWithNibName:#"bloop2ViewController" bundle:nil];
I was getting this problem and the fix was to make sure both
I set the NIB name in the view controller beneath the tab bar in the main window xib, and
the class name was set in the sub-viewcontroller.
This page was helpful for me.
I just experienced this issue. In my case the cause was the implementation code for MyTableViewController was being excluded from the current build configuration. Hope that helps someone.
Yet another way this can bite you. I had tossed out the xib for a view and started over. No matter what I did, the view threw this exception on load. After pulling my hair out for several hours, I finally deleted the app from the simulator and that fixed it. Somehow the old xib wasn't being replaced on install.
After 2 hours on this i forgot to
#synthesize tableView = _tableView;
Hope it helps
Mário