Import swift class into objective c storyboard - ios

Im trying to integrate implement the project https://github.com/ariok/BWWalkthrough into my objective c project.
I have an objc bridging header that Xcode automatically made for me
I translated the ViewController.swift code as such
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Walkthrough" bundle:nil];
BWWalkthroughViewController *walkthrough = [sb instantiateViewControllerWithIdentifier:#"walk"];
BWWalkthroughPageViewController *page_zero = [sb instantiateViewControllerWithIdentifier:#"walk0"];
BWWalkthroughPageViewController *page_one = [sb instantiateViewControllerWithIdentifier:#"walk1"];
BWWalkthroughPageViewController *page_two = [sb instantiateViewControllerWithIdentifier:#"walk2"];
BWWalkthroughPageViewController *page_three = [sb instantiateViewControllerWithIdentifier:#"walk3"];
walkthrough.delegate = self;
[walkthrough addViewController:page_zero];
[walkthrough addViewController:page_one];
[walkthrough addViewController:page_two];
[walkthrough addViewController:page_three];
[self presentViewController:walkthrough animated:YES completion:nil];
and I import the swift classes like so:
import "SkipTheLine-Swift.h"
My bridging header file's name is "SkipTheLine-Bridging-Header.h"
now, when I run the code, I get this
2015-04-25 16:47:46.740 SkipTheLine[1631:215786] Unknown class BWWalkthroughViewController in Interface Builder file.
2015-04-25 16:47:46.754 SkipTheLine[1631:215786] -[UIViewController setDelegate:]: unrecognized selector sent to instance 0x12651cf90
2015-04-25 16:47:46.755 SkipTheLine[1631:215786] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setDelegate:]: unrecognized selector sent to instance 0x12651cf90'
* First throw call stack:
(0x1838aa530 0x19482c0e4 0x1838b15f4 0x1838ae3ac 0x1837b2c4c 0x10009c494 0x1880eca14 0x1880d5d08 0x1880ec3b0 0x1880ec03c 0x1880e5590 0x1880b8e60 0x18835846c 0x1880b73d0 0x183862d34 0x183861fd8 0x183860088 0x18378d1f4 0x18cbb76fc 0x18811e10c 0x10009e174 0x194eaaa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
Any ideas as to how I can use the swift code in interface builder?

Figured it out!
You just need to edit the MODULE in the interface builder to the name of the project!!

Related

prepareForSegue for TabBarController

I'm trying to pass data from my ViewController to TabBarController by using Objective-C. I'm trying to assign some data to "bottomTabEventList" (which is a property of my custom TabBarController class). Unfortunately, my program crashes by giving unrecognized selector instance error/warning.
In custom header of TabBarController class, named BottomTabview:
#interface BottomTabView : UITabBarController <UITabBarControllerDelegate>
#property(strong,nonatomic)EventList *bottomTabEventList;
#end
And prepareForSegue method in ViewController.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
BottomTabView *btw = [segue destinationViewController];
//checking
if(btw == nil)
NSLog(#"btw in viewController is nil");
else
NSLog(#"btw in viewController is NOT nil");
if(self.eventList.eventList == nil)
NSLog(#"eventList in viewController is nil");
else
NSLog(#"eventList in viewController is NOT nil"); //end of checking
btw.bottomTabEventList = self.eventList; //This is where crash appears
}
Exact crash log is:
-[ViewController setBottomTabEventList:]: unrecognized selector sent to instance 0x7fe923c6ba00
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController setBottomTabEventList:]: unrecognized selector sent to instance 0x7fe923c6ba00'
Segue is from ViewController to BottomTabView and its type is "Present Modally". I'd really appreciate if you can help/guide me. Thanks in advance.
The problem seems to be that btw is not actually of type BottomTabView and is just a UIViewController hence the crash log giving:
[ViewController setBottomTabEventList:]: unrecognized selector sent to instance
As UIViewController does't know what BottomTabEventList is.
You need to make sure that btw is actually a BottomTabView instance.
Do a little introspection and I bet it will not go into this statement:
if ([btw isKindOfClass:[BottomTabView class]]){
btw.bottomTabEventList = self.eventList;
}

MPMoviePlayer crashing on getting out and in the app

I get this error:
-[MPInlineVideoFullscreenViewController player]: unrecognized selector sent to instance 0x15e63fe90
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MPInlineVideoFullscreenViewController player]: unrecognized selector sent to instance 0x15e63fe90'
Using iOS 8, the language is Objective-C. But I have this same code in the if statement like this in applicationDidBecomeActive and it does not crash:
UIViewController *vc = ((UINavigationController*)self.window.rootViewController).visibleViewController;
if([vc isKindOfClass:[VideoViewController class]]) {
VideoViewController *vca = vc;
if(vca.player.playbackState == MPMoviePlaybackStatePaused){
[vca.player play];
}
But if I use it on the different MPMoviePlayer, and it is fullscreen. I switch to a different app, and back, it crashes. Buy why not with the other movie controller. Also, the other one does not show any playback controls, while this one which crashes does.

unrecognized selector sent to instance

I am trying to get a pop up menu on iPhone.
The main app is using storyboard, but the pop up is a separate xib file that I load:
menu = [[UIViewController alloc] initWithNibName:#"SimpleMenuController" bundle:nil];
[self.view addSubview:menu.view];
and I slide it in and out with animation when pressing a button.
that works fine, but I get a problem when I try to press a button inside that pop up menu
I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UIViewController PressCategory:]:
unrecognized selector sent to instance 0x8d3c040'
I have connected the button to PressCategory function
I have connected the view to the file owner.
What I have noticed is that my ViewController is called SimpleMenuViewController, that is where the PressCategory function is, so of course it will not find the selector. But I don't know what I am doing wrong in connecting in the xib file.
Change your code to:
menu = [[SimpleMenuViewController alloc] initWithNibName:#"SimpleMenuController" bundle:nil];
so that you're instantiating the correct class.
Do you have PressCategory function in your SimpleMenuViewController?
If yes, then check weather its parameterized or not.
Declare function in .h file like this:
-(IBAction)PressCategory:(UIButton *)sender;
Define it in .m file like this:
-(IBAction)PressCategory:(UIButton *)sender {
// write your code here
}

_setViewDelegate unrecognized selector sent to instance

I am getting this exception:
2012-10-11 14:27:05.039 SunriseAlarm[2297:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PickerViewController _setViewDelegate:]: unrecognized selector sent to instance 0x1e56fff0'
I have this code in the appDelegate.m file
PickerViewController *pvc = [[PickerViewController alloc] initWithNibName:#"PickerView" bundle:nil];
self.window.rootViewController = pvc;
I have already set the class of the nib to the custom class and it is not UIViewController. Please see image below.
Please let me know what do you think I am doing wrong.
Thank You,
Venkat Rao
You did set PickerViewController class for UIView, it's not correct, return back and set PickerViewController for File's owner

NSLayoutConstraint crashes ViewController [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
presentViewController: crash on iOS 6 (AutoLayout)
I'm getting this error when clicking on a button in my app:
2012-06-28 21:43:36.860 AppName[2403:707] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint'
*** First throw call stack:
(0x3568788f 0x37a2e259 0x35687789 0x356877ab 0x333a254d 0x333a26bb 0x333a2423 0x33333001 0x332a13c7 0x3317ec59 0x330f4c17 0x330ff267 0x330ff1d5 0x3319e59b 0x3319d367 0x331f86a7 0x8fb11 0x355e13fd 0x330d6e07 0x3319c5e7 0x355e13fd 0x330d6e07 0x330d6dc3 0x330d6da1 0x330d6b11 0x330d7449 0x330d592b 0x330d5319 0x330bb695 0x330baf3b 0x3727a22b 0x3565b523 0x3565b4c5 0x3565a313 0x355dd4a5 0x355dd36d 0x37279439 0x330e9cd5 0x8f6cb 0x8f628)
terminate called throwing an exception
The error complains on this line of code:
-(IBAction) goToAbout {
About *screen = [[ About alloc] initWithNibName:#"About" bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
}
The error appears only on my iPhone but not on the simulator...
You must uncheck the box in your NIB that says "use auto layout" before you try to run this thing on a device that doesn't support the new NSLayoutConstraint class.

Resources