Error in simulator when try run an app - objective-c

I created app with using storyboards. My app has a table, some buttons and labels.
When I try to run my app simulator generates an error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x719de00'
UIViewController tableView:numberOfRowsInSection: means that I can't use "numberOfRowsInSection" with "UIViewController"?
I tried to use "UITableViewController" instead but with this controller I can't locate the buttons and labels in right place for me.
What I do wrong?
Thanks.

Once you Add the UITableView and set Datasource and Delegate, we must use some UITableview Delegate Methods. such as NumberOfRowsInSection, NumberOfSection, and so on.
Kindly Use the Essential Delegate Methods or Remove the UItableView.

You need to delegate the UITableView to the UIViewController, open the Connections inspector and drag the "delegate" and "dataSource" entries to the main view controller on the storyboard.

Related

Multiple collection view on one view controller

I have 4 collection view on one view controller and different data has to be fetched from api for every view controller.
The data has been fetched one by one but how to fetch data for all collection view at the same time.
As i know i can use CollectionView DataSource and delegate methods for once and i have to implement methods for 4 collection view in one but it app crashes giving error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HomeScreenViewController collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance.
Can anyone tell me how to solve this problem??
I would strongly suggest that you use a separate UICollectionViewController for each of your collection views. This can be achieved easily in the InterfaceBuilder via ContainerViews.
Coordinating all four CollectionViews in one View Controller is possible - but ugly.

Assertion failure in -[UITableView layoutSublayersOfLayer:]

I want to use an UISearchDisplayController on UIViewController, that includes an UITableView.
I use Autolayout. When i try to put the SearchBar (_searchBar) in the tableHeaderView with
self.tableView.tableHeaderView = _searchBar;
I get the error
'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.'
Disabling Autolayout, the error disappears, but i need Autolayout...
The error appears, when I use Custom Cells or StandardCells...
The error appears, when the TableView has no rows...
As a general solution to this problem, or at least a way of finding the cause of it:
Turn on exception breakpoints
Subclass UITableView and override layoutSublayersOfLayer:, just calling super
Run your app - you will stop in your new method
In the debugger, type po [self _autolayoutTrace]
This will show you a printout of every view in the window, with the views where auto layout has not been able to come up with a solution highlighted by asterisks or AMBIGUOUS LAYOUT. These are the views you need to investigate the constraints for.
When adding a subview to UITableView there are some specific requirements for the subview. Consider adding the subview to another view(superview) in your controller instead of UITableView.
"Auto Layout still required after executing -layoutSubviews" with UITableViewCell subclass

how to solve run time error of loaded the "DetailViewController" nib but the view outlet was not set.'

I am beginner of iPhone here come the error of run time of
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '-[UIViewController
_loadViewFromNibNamed:bundle:] loaded the "DetailViewController" nib but the view outlet was not set.'
give any suggestion and source code which is apply in my code....
it would be easier to help you if you could post the code of your uiviewcontroller. I guess you have some IBOutlets which aren't connected properly between your UIViewController class and the corresponding Controller on the Storyboard
You have to connect your root view of the nib file to the view property of the files owner (your DetailViewController).

iPhone program immediately exits when loading a View from an NIB

The app in question is a simple sample program. In my view controller header, I have the button instantiated as such:
#interface ObscurelyNamedViewController : UIViewController {
UIButton *yoButton;
}
#property(nonatomic, retain) IBOutlet UIButton *yoButton;
- (IBAction)yoButtonPressed:(id)sender;
yoButtonPressed: is implemented as such:
[yoButton setTitle: #"I said 'yo', jammit!" forState: UIControlStateNormal];
// repeat for other button states
.
.
.
In Interface Builder, I have connected the Touch Up Inside event of the UIButton to the yoButtonPressed method in the File's Owner of the ObscurelyNamedViewController to recognize the touch. In return, I have connected the outlet of the File's Owner back to the yoButton, so as to enable the updating of it's title.
When I build and run, I get no errors, but nothing displays and the app immediately quits. The only other thing living in IB is a UIImage view. Am I missing something or have I wired something incorrectly?
EDIT: In the console, I see the following message:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "BradiiCaliiViewController" nib but the view outlet was not set.'
This likely has nothing to do with that action. You said, "nothing displays and the app immediately quits", which means that the action was never sent.
Need your message from the Console, but check
Did you use initWithNibName? If so, did you get the name exactly right?
Are you doing anything with Outlets in init? You should not -- and do it in viewDidLoad.
Knowing the message in your console will help us give you the real answer though.
Edit: based on your console message
Double-click .xib file to go to IB
Click on File's Owner
Go to Connections Inspector
The view outlet is not set (right?) -- drag the circle to the view icon in the Document Window.
(I am sorry, but I don't have IB in front of me -- this is from memory -- look around for the view outlet in connection inspectors if I am wrong about the exact location)
Moved from comment on Lou Franco answer:
BradiiCaliiViewController complains that it doesn't have a view even after NIB was loaded. You have to connect view outlet of File's Owner to your view in BradiiCaliiViewController's XIB.

Push TabBarController to a View

How can i push a TabBarController to a View?
The App is View-Based. In the App I have a XIB with a TabBarController and I want to push the TabBar to the display. I have done everything, and now I don't know what I'm doing wrong.
Here is the code that should push the TabBarController:
- (void)showTabBar {
TabBar *tbc = [[TabBar alloc] initWithNibName:#"TabBar" bundle:nil];
[self presentModalViewController:tbc animated:YES];
[tbc release];
}
At this moment there is an empty view in the XIB. So the display is white when I run this code. There is also the TabBarController, which I want to see on the display.
Thanks for your help.
UPDATE:
I should say that these are two different classes. The class where the function "showTabBar" is based should push the TabBarController. The second class is TabBar. TabBar is the delegate of the TabBarController.
So I have modified the answer like this, but I have tried both:
[self presentModalViewController:tbc.tabBarController.view animated:YES];
The error now looks like this:
Incompatible Objective-C types 'struct UIView *', expected 'struct UIViewController *' when passing argument 1 of 'presentModalViewController:animated:' from distinct Objective-C type
UPDATE:
Hey the error has gone away. Cool. ;)
But the app is terminating. I've seen this behavior before, but I didn't know what to do.
The debugger console says this:
2011-01-27 15:49:32.629 Touch[3657:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <StartUp: 0x9300f20>.'
Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html
What this mean is, this is not "allowed" and Apple can or may in the future reject your application. UITabBarController is intended to be added to the root view(window) in your application delegate. If you want a tabbar to be pushed on later you need to use the UIToolBar with e.g. uisegmentedcontrol or the toolbar buttons.
Even though some apps does this(e.g Wordpress app) you will later find out that you will run onto some issues in the console when presenting viewcontrollers modally.(A warning will be given).