Storyboard screenshot
In the Xcode 4.6 Storyboard i've 2 ViewControlers, one which holds the buttons and the other a labelView, passing a string "Home Tapped" on the tap of the home button
Heres the ViewController.m code
#import "ViewController.h"
#import "ViewController2.h"
#interface ViewController ()
#end
#implementation ViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"Home"])
{
NSString *message = #"Tapped on home";
ViewController2 *vc = [segue destinationViewController];
vc.labelString = message;
}
}
ViewController2.h
#import <UIKit/UIKit.h>
#interface ViewController2 : UITableViewController
#property(nonatomic,strong) UILabel *mylabel;
#property(nonatomic,strong) NSString *labelString;
#end
And the error
Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'Home'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
*** First throw call stack:
(0x1c91012 0x10cee7e 0x468f31 0x45ab99 0x45ac14 0x10e2705 0x162c0 0x16258 0xd7021 0xd757f 0xd66e8 0x45cef 0x45f02 0x23d4a 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x1beb7e3 0x1beb668 0x12ffc 0x28dd 0x2805)
libc++abi.dylib: terminate called throwing an exception
(lldb)
You need to make your NavigationController the entry point for your storyboard. Right now it is View Controller, which is indicated by the arrow pointing to it with no source.
Related
While trying to run my tab-bar app with many different features such as UITableView and mapview with a annotation, I recently added a webview on my first tab in my firstviewcontroller. As far as I know, there's nothing wrong with the coding there, though ever since I tried adding the webview on my first tab I keep getting the breakpoint/error while trying to run the app : Thread 1: signal SIGBRT.
I've read around some, and someone said that if I change mi xib file /storyboard's deployment to iOS 5.0 instead of 6.0 (wich I'm currently using) and not having "Use Autolayout" checked it should get rid of it. Though It didn't. Any thoughts or solutions to this?
Here's the coding for my firstviewcontroller.h
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#end
firstviewcontroller.m
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webView;
- (void)viewDidLoad
{
NSString *website = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:website];
NSURLRequest *requestUrl = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestUrl];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
main.m :
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); // <--- HERE's where it says SIGBRT
}
}
All output:
2013-01-04 11:27:06.697 My Corp[784:13d03] Unknown class ViewController in Interface Builder file.
2013-01-04 11:27:06.716 My Corp[784:13d03] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FirstViewController 0x808fbf0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myWebView.'
*** First throw call stack:
(0x1800012 0x11c5e7e 0x1888fb1 0xc72711 0xbf3ec8 0xbf39b7 0xc1e428 0x32a0cc 0x11d9663 0x17fb45a 0x328bcf 0x1ede37 0x1ee418 0x1ee648 0x1ee882 0x20fed9 0x20fd14 0x20e1ea 0x20e06c 0x20c1cc 0x20c9b6 0x1f0753 0x1f0a7b 0x1f1964 0x154877 0x15b5a3 0x153eed 0x13db56 0x13ddbf 0x13df55 0x146f67 0x10afcc 0x10bfab 0x11d315 0x11e24b 0x10fcf8 0x1cc9df9 0x1cc9ad0 0x1775bf5 0x1775962 0x17a6bb6 0x17a5f44 0x17a5e1b 0x10b7da 0x10d65c 0x289d 0x27c5)
libc++abi.dylib: terminate called throwing an exception
(lldb)
The mistake you have done was clearly stated in the crash report
[<FirstViewController 0x808fbf0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myWebView.'
To solve that go to your XIB of that Class right click on the File owner located on the left side pane of InterfaceBuilder. You will find an object with name myWebView with yellow warning icon, click remove on that outlet connection and compile your code. You have connected the outlet and later you remove the IBOutlet in the code and forget to remove the connection in the XIB.
set
UIWebViewDelegate in .h file and in xib attach delegate of webview
I have a Universal app with UISplitViewConroller. I am using storyboards.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];
LeftViewContrller *lcontroller = (LeftViewContrller *)masterNavigationController.topViewController;
id<SplitViewDelegate> rightController = (id<SplitViewDelegate>)[splitViewController.viewControllers objectAtIndex:1];
lcontroller.delegate = rightController;
}
I have a left and right controller for UISplitViewController app.
LeftViewController has a custom delegate, which is set as RightViewController.
//Custom delegate
#protocol SplitViewDelegate <NSObject>
- (void) matchSelectionChanged:(NSString *)curSelection;
#end
//LeftViewContoller
#interface LeftViewContrller : UITableViewController {
id<SplitViewDelegate> _delegate;
NSMutableArray *_matches;
}
#property (strong) id<SplitViewDelegate> delegate;
#property (strong) NSMutableArray *matches;
#end
RightViewController implements this delegate protocol. However, when cell inside row is clicked in LeftViewController the delegates failing.
//RightViewController
#interface RightViewController : UIViewController <SplitViewDelegate>
#property (weak,nonatomic) IBOutlet UILabel *matchLabel;
#end
//Implementation of RightViewController
- (void) matchSelectionChanged:(NSString *)curSelection {
self.matchLabel.text = curSelection;
//[self refresh];
}
//Did select row in LeftViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableString *s = [[NSMutableString alloc] initWithString:#"Row selected"];
if (_delegate != nil) {
[s appendFormat:#" %d ", indexPath.row];
[_delegate matchSelectionChanged:s];
}
}
//Get error
CustomViewTab[1200:11303] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController matchSelectionChanged:]: unrecognized selector sent to instance 0xda6a770'
* First throw call stack:
(0x1559052 0x1da8d0a 0x155aced 0x14bff00 0x14bfce2 0x1204e 0x62071d 0x620952 0x25986d 0x152d966 0x152d407 0x14907c0 0x148fdb4 0x148fccb 0x2500879 0x250093e 0x590a9b 0x1df8 0x1d55)
terminate called throwing an exception
I see didSelectRowAtIndex called but then RightViewController's matchSelectionChanged:(NSString *)curSelection never gets called.
Bit of an old question but I stumbled up on it and at a glance do you have the correct delegate?
#interface RightViewController : UIViewController <UISplitViewControllerDelegate>
I'm looking at iOS7 so maybe its changed since iOS5
I am trying to call an action (changeMainNumber) in a main view controller from a modal view controller. The action should change the UILabel mainNumber to 2. In ViewController.h, I have:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UILabel *mainNumber;
}
#property (nonatomic, retain) UILabel *mainNumber;
-(IBAction)changeMainNumber;
ViewController.m:
#import "ViewController.h"
#implementation ViewController
#synthesize mainNumber;
- (IBAction)changeMainNumber:(id)sender {
mainNumber.text = #"2";
}
The next view controller is the modal view controller.
ModalViewController.h:
#import <UIKit/UIKit.h>
#class ViewController;
#interface ModalViewController : UIViewController {
}
-(IBAction)callChangeMainNumber:(id)sender;
and ModalViewController.m:
#import "ModalViewController.h"
#implementation ModalViewController
- (IBAction)callChangeMainNumber {
ViewController *viewController = [[ViewController alloc] init];
[viewController changeMainNumber];
}
With this setup the app keeps crashing when callChangeMainNumber is called and I can't figure out what is wrong. Any help you can provide is appreciated!
The code you posted from your ModalViewController is not referencing your ViewController. You are creating a new one in your code. The best solution to your problem would be to make your ViewController a delegate to the ModalViewController.
So in your ModalViewController.h file you should have this code above your #implementation.
#protocol ModalViewControllerDelegate
- (void)shouldChangeMainNumber;
#end
Then in your #implementation of the header have:
#property (nonatomic,assign)IBOutlet id <ModalViewControllerDelegate> delegate;
Now in the .m file where you have your IBAction method, tell the delegate that you want it to change the main number.
- (IBAction)callChangeMainNumber {
[self.delegate shouldChangeMainNumber];
}
Then in your ViewController.m file you need to set yourself as the delegate of the ModalViewController, usually in viewDidLoad is a good place to put it. So create a property in your header for the ModalViewController first and synthesize it, then add this to viewDidLoad.
self.modalViewController.delegate = self;
and finally you need to implement the delegate method in your .m file somewhere
- (void)shouldChangeMainNumber {
mainNumber.text = #"2";
}
I need to present a modal view controller and be notified when it is dismissed or notified that I need to dismiss it, looking here I am still confused:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14
I have my mainViewController and myModalView controller and I have the following code that needs to be implemented but not sure where - first up delegate protocal:
#protocol DataSyncDelegate <NSObject>
-(void) doneWithSync;
#end
which controller.h does this go in? I am assuming my modalViewController.h
second is my implementation:
-(void) doneWithSync {
[self dismissModalViewControllerAnimated:YES];
}
which controller.m does this go in? I am assuming my mainViewController.m
I also have the delegate properties that needs to be aded:
id delegate;
#property (nonatomic, retain) id delegate;
which controller.m does this need to go in? I am assuming my modalViewController.h
and here is how I am presenting the modalViewController from my MainViewController:
DataSyncViewController *dataSyncViewController = [[DataSyncViewController alloc] initWithOptions:FALSE];
dataSyncViewController.delegate = self;
[self presentModalViewController:dataSyncViewController animated:NO];
[dataSyncViewController release];
As of right now this gives me the following error:
-[DataSyncViewController setDelegate:]: unrecognized selector sent to instance 0x5952e20
What am I missing here?
EDIT - HERE IS MY MODAL VIEW CONTROLLER .H
#import <UIKit/UIKit.h>
#protocol DataSyncDelegate
-(void) doneWithSync;
#end
#interface DataSyncViewController : UIViewController {
id <DataSyncDelegate> delegate;
}
#property (nonatomic, retain) id <DataSyncDelegate> delegate;
#end
EDIT - MAIN VIEW CONTROLLER .H AND .M
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "DataSyncViewController.h"
#interface LoginViewController : UIViewController <DataSyncDelegate>{
}
#end
HERE IS THE CREATION OF THE MODAL:
DataSyncViewController *dataSyncViewController = [[DataSyncViewController alloc] initWithOptions:FALSE];
dataSyncViewController.delegate = self;
[self presentModalViewController:dataSyncViewController animated:NO];
[dataSyncViewController release];
HERE IS MY IMPLEMENTATION OF THE DELEGATE:
-(void) doneWithSync {
[self dismissModalViewControllerAnimated:YES];
}
And now everything looks to wire up correctly in the compiler but I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[DataSyncViewController setDelegate:]: unrecognized selector sent to instance 0x59e4b40'
Your main view controller IS the delegate and should implement the protocol. Your modalView has a delegate that it calls when it is being dismissed.
Alright, in my rootViewController, I am able to push another viewController that I defined myself onto the screen. However, when I make any connections between that viewController and its own .h file, the program just hangs and crashes, giving me this error:
2010-06-04 15:36:13.944 pooldocfinal[11971:20b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label1.'
That happens when i don't connect anything besides that one UILabel. Here is the code I use to declare/push the view (named balanceViewController):
- (IBAction) pushedBalanceButton
{
balanceViewController *controller = [[balanceViewController alloc] initWithNibName:#"balanceViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
And here is the .h file of the view that I am pushing, it has only one thing in it:
#import <UIKit/UIKit.h>
#interface balanceViewController : UIViewController {
IBOutlet UILabel *label1;
}
#end
And like I said, everything works unless I actually make a connection in Interface Builder between anything in balanceViewController.xib and balanceViewController.h (in this case, it is the one UILabel object).
You should alloc a balanceViewController, not a UIViewController.
I believe if you have an IBOutlet, you need to define getters/setters. That's what Key Value coding compliant means. You can do this via #property statements and #synthesize statements, or manually if you so choose.
#interface balanceViewController : UIViewController {
IBOutlet UILabel *label1;
}
#property (nonatomic, retain) IBOutlet UILabel *label1;
#end
Then add
#synthesize label1;
to your implementation
EDIT - PS, don't forget to [label1 release] in your dealloc method