I am working on an app where the user has the possibility to add products and those products are then displayed in a TableView. I created a TableViewController with static cells and two sections and I want to hook the cell in the second section with another TableViewController.
I dragged the TableViewController from the object library, embedded it in a navigation controller and made a push segue from the cell to the NavigationController but when I try to run the app I get the following error message in the output window:
2013-03-20 09:55:32.981 STAM[725:c07] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
First throw call stack:
(0x1d04012 0x11e8e7e 0x22a5b0 0x22a098 0x585da3 0x577ad9 0x577b54 0x1df899 0x1dfb3d 0xbe6e83 0x1cc3376 0x1cc2e06 0x1caaa82 0x1ca9f44 0x1ca9e1b 0x1f3c7e3 0x1f3c668 0x13065c 0x2a6d 0x2995)
libc++abi.dylib: terminate called throwing an exception
Here's a screenshot form my storyboard.
Thank you very much!
Granit
Your UINavigationController is at the wrong place. It should be before the UITableViewController.
You can select the UITableViewController from story board then from menu: Editor > Embed In > Navigation Controller.
You can get more info about the navigation stack from the reference guide.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
Related
I am just starting up in Xamarin iOS (native) development, so bear with me as I try to explain what we're trying to do.
I have a single storyboard Main.storyboard, where I have designed and built a single Tab Bar controller, and several custom View Controllers, some of which are linked up as tabs. On the first tab, I have a login screen if they are not logged in. However, if they ARE logged in, I want to show the view defined in a different View Controller (Account) that exists within the same storyboard.
In the ViewDidLoad() override for the LoginController, I have the following code that I thought would show the "logged in" Account View Controller:
this.PresentViewController(new AccountController(), true, null);
This line of code executes without error, however the Login view is still shown. The ViewDidLoad() override in the AccountController does NOT fire.
Question 1: Is this the right method to call in order to replace your current view controller with another?
Now, if I place this exact same line of code in an async button handler method (particularly, the Facebook SDK Login Button's Completed event), it actually hits the ViewDidLoad() override in the AccountController, but I receive a NullReferenceException on a line that is simply referencing a button that is defined within the storyboard/view.
Question 2: Why would the same exact call from an event handler behave so differently?
Lastly, if I set the AccountController up as a tab bar tab instead, the code in ViewDidLoad() that is referencing the button works as expected.
Up to this point, all of my loading and unloading of different views was being handled automagically by the UITabBarController, but now that I'm trying to do some manual transitions, I am having a tough time finding appropriate documentation that isn't outdated and applies to my specific setup.
Generally , we can use PresentViewController to navigate to another page in Navigation Controller , this should be a safe and easy way.
Push :
Pop :
However , PresentModalViewController is a model ViewController , although it seems like the same as PresentViewController . It not needs to be in the stack of Navigation Controller ,and always used in a single view needs to show temporarily , soon will dismiss it.
If scene needs to reset RootViewControllerwhen runtime , this can be thought as the third way to navigate .
var storyboard = UIStoryboard.FromName("Main", null);
var anotherController = storyboard.InstantiateViewController("AnotherViewController") as AnotherViewController;
UIWindow window = UIApplication.SharedApplication.KeyWindow;
if(window != null)
{
window.RootViewController = anotherController;
}
In addittion , this will be un-safe way to use , better used them in current ViewController dismiss method :
DismissViewController(true, () => {
// Set Root View Controller
});
While Junior's answer pointed me in the right direction, the ultimate solution was to adjust the first tab to be a new NavigationController, and use (manual) Segues to navigate between the views.
The segues were added to the storyboard, and the View Controllers ultimately make calls to PerformSegue('namedSegue', this) to navigate to the next view.
I am developing an application using Xcode 7 and Swift 2. I recently discovered an error in my code. In the debugger log (I think that is what it is called) , it printed this:
[AppDeveloper] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=7 "Ad was unloaded from this banner" UserInfo={ADInternalErrorCode=7, NSLocalizedFailureReason=Ad was unloaded from this banner, ADInternalErrorDomain=ADErrorDomain}
I did some research and found out that I needed this code:
iAdBannerView.delegate = self
In my viewDidLoad method. I tried it, and I no longer recieved the error. However, I have two viewControllers. Both contain iAds. In the original view controller, ViewController.swift, the code workds. In the view controller that I later added, AboutViewContoller, I get this error:
Cannot assign a value of type 'AboutViewController' to a value of type 'ADBannerViewDelegate?"
Could someone please show me my error in my code?
Earlier, I had:
class AboutViewController: UIViewController {
I forgot the ADBannerViewDelegate. The correct code is:
class AboutViewController: UIViewController, ADBannerViewDelegate {
Thanks to Charles A. and Daniel Storm for helping out!
I want to do some stuff from the appDelegate in Xcode. One of these things are to change a UILabel.
ViewController *viewController = [[UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:#"id"];
viewController.label.text = #"heeej";
I was told this would do the trick. Doesn't work. Label doesn't change. Does anyone know what the problem is?
There are several problems:
Don't do anything in the AppDelegate except for loading the window an the initial view controllers (if needed).
You are instantiating a new view controller in the first line. I assume you already have a view controller and you want to change the label in that view controller. Than you need a reference to that view controller and use this reference to send messages to it.
The label should not be a property of the view controller. You should try to follow the design pattern Model-View-Controller or the pattern Model-View-ViewModel. Ask you preferred search engine what those are if you don't know.
id as an identifier for anything in Objective-C is a bad idea because this is used as an object type.
Edit: You don't need a reference to change a property in the view controller. Use notifications to update the label. The system sends a notification with the name UIApplicationWillEnterForgroundNotification' (see [here][1]). Add the view controller as an observer to the[NSNotificationCenter defaultCenter]` for this name and react on the notification. Read the Apple documentation if you don't know what I am talking about.
I am trying to feed the content of a masterview after creating a project based on the master/detail app template.
I have basically a model that content all my data which might change later on. I want to feed automatically the content of the tableview by providing the number of rows per section and number of sections that has this model.
I manage to do so by overriding the following 2 functions:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
I got a NSRangeException exception though if i didn't edit the storyboard for the Master View Controller - Master Scene such that it reflects a larger number of sections and rows in sections than my model has.
e.g: I left the storyboard for the Master Scene with 1 section and 1 row. If i return 2 in the numberOfRowsInSection function my program will crash at run time with this NSRangeExceptionError error:
2011-10-10 14:38:53.042 sample_project[3636:f803] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x13bb052 0x154cd0a 0x13a7674 0x432805 0x24227a 0x1ed548 0x1ef722 0x9f7c7 0x9f2c1 0xa228c 0xa6783 0x51301 0x13bce72 0x1d6592d 0x1d6f827 0x1cf5fa7 0x1cf7ea6 0x1d8330c 0x114c6 0x11bd6 0x20743 0x211f8 0x14aa9 0x12a5fa9 0x138f1c5 0x12f4022 0x12f290a 0x12f1db4 0x12f1ccb 0x112a7 0x12a9b 0x25e2 0x2555)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language: auto; currently objective-c
(gdb)
Does anyone see a reason for this behavior? Am I missing something? Do I need to make some extra initialization that will set a default size for the tableview in the didLoad function of the controller?
I found out that the default table view Content attribute is set to static. You can change it to Dynamic Prototypes. You need to provide a identifier for the cell: I am not sure how this is used though. This solved the crash i was mentioning above.
More code of yours will actually help, but anyways,
There are some changes made in UIKit in IOS5, kindly check the following link, so that you dont conflict anywhere else in the code.
IOS 5 Release Notes
There is a change in the NSIndexPath too, check that particularly. As per apple docs,
The indexPathForRow:inSection:, section, and row methods of NSIndexPath now use NSInteger instead of NSUInteger, so that these types match with methods defined on UITableView.
If you find the answer, please share.
I have a simple tabbar app
I have created a XIB file and assigned it to a tab, and when I touch the tab, it accurately switches
I added a simple IBAction
in Tab1.h
-(IBAction)pleasebeep:(id)sender;
in Tab1.m
-(IBAction)pleasebeep:(id)sender
{
NSLog(#"honk");
}
In interface builder I have created a button and linked it to the Owner and action "pleasebeep"
It compiles and launches.
When I click the button, the app crashes and I get a "-[UIViewController pleasebeep:]: unrecognized selector sent to instance 0x7b975c0
2011-10-06 04:32:25.648 FirstProject[8029:11903] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController pleasebeep:]: unrecognized selector sent to instance 0x7b975c0'
* First throw call stack:
(0x12de082 0x146fd0a 0x12dfd1d 0x1244f70 0x1244d52 0x12dfef9 0x37c542 0x37c4da 0x421576 0x421a3f 0x420cfe 0x3a1810 0x3a1a36 0x388234 0x37ba29 0x1ece10d 0x12b21f5 0x12170a2 0x121598a 0x1214e34 0x1214d4b 0x1ecc9dd 0x1eccaa2 0x379a1b 0x2749 0x26c5)
terminate called throwing an exceptionCurrent language: auto; currently objective-c"
Any idea where to hunt for the problem?
Have you set the right Custom Class to the File's Owner? Maybe it's still set to the default class 'UIViewController'