How to create project without story board in xcode 6 (swift)? - swift

Can any one has practiced creating project in xcode6 (swift) without storyboard.
I am able to implement
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window!.backgroundColor = UIColor.whiteColor()
self.window!.makeKeyAndVisible()
var viewController: ViewController? = ViewController(nibName: "ViewController", bundle: nil)
self.navigationController = UINavigationController(rootViewController: viewController)
self.window!.rootViewController = self.navigationController
return true
}
but it fails with following error
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ViewController" nib but the
view outlet was not set.'
so i tried to relate file's owner UIView with xib, but i am unable to see UIView in file's owner property.
See the screen below
EDIT
Thanks Alex but from the second last point from HERE i am unable to find any view.
See the screen attached

I resolve my issue..
See the screen
Something strange with xcode6 beta, i am not sure whats wrong with it.

In Xcode 6 , you will get two custom class field in file inspector.you should enter your view controller name in second custom class field. when you enter the name then you can see view outlet under file owner properties.

Please ensure you have connected correctly your class with nib file. Especially, File's Owner setting. The same steps sequence for Swift as for Obj-C.
Try to reload XCode and re-save .nib file
See the instructions from here:
https://stackoverflow.com/a/6395750/2429147
or here:
https://stackoverflow.com/a/17321200/2429147

Related

PushViewController shows Black Screen

i have a problem with my App.
I´m not an experienced programmer, so maybe it´s just a simple solution. I thought this problem exists because i´m just trying things and play with my app so i made a new App and there´s the same problem.
When i push to a ViewController with navigationController?.pushViewController(PinkViewController(), animated: true).
I´m getting just a black screen. If i have a code like
Label.text = "String in viewdidload of the PinkViewController(). I get the following error at this line of code:
fatal error: Unexpectedly found nil while implicitly unwrapping an
Optional
I searched the web and i didn´t find any solutions for this problem. I hope you can help me.
The reason why it crashes is that your label is probably defined as an #IBOutlet that is connected to a UILabel in your storyboard's PinkViewController. However, when you instantiate PinkViewController with an empty constructor, you're not "using the storyboard-way" and your label outlet (which is non-optional, because it's likely to have an exclamation mark there) could not have been connected to the storyboard instance of your view controller.
So what you should do is one of these options:
If you defined PinkViewController in the storyboard, you'd have to instantiate it in a nib kind of way, for example:
In your Storyboard, select the view controller and then on the right side in the Identity Inspector, provide a Storyboard ID. In code you can then call this to instantiate your view controller and then push it:
let pinkViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "yourIdentifier")
Even better, you create a Segue in the storyboard by control-dragging from the current VC to PinkViewController. There's lots of tutorials for creating Segues online. Don't forget to provide an Identifier for the Segue in the Storyboard, if you want to trigger it programmatically. This can be done by calling
self.performSegue(withIdentifier: "yourIdentifier", sender: nil)
If you want to trigger that navigation upon a button click, you can even drag the Segue from the button to PinkViewController, that way you wouldn't even need to call it in code.
If you defined PinkViewController programmatically only (by creating a class named like that which conforms to UIViewController), you might wanna instantiate it with PinkViewController(nibName: nil, bundle: nil) (notice the arguments instead of an empty constructor) and then push it with your provided code.
Hope that helps, if not, please provide further code / project insight.

Xcode 11.2.1 - Swift 5 - Can't change main storyboard "Main" to another storyboard "Start"

I have created a new storyboard named "Start.storyboard", but when I change Main Interface to "Start" nothing happened, The app just started with default storyboard "Main.storyboard".
I'm using Xcode 11.2.1 and iOS 13.2.3
Also I have tried to change the rootViewController from (AppDelegate) didFinishLaunchingWithOptions as the code below:
let sb = UIStoryboard(name: "Start", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "PhoneVC")
self.window?.rootViewController = vc
but I got the same result, Main storyboard can't be changed.
Go to Info.plist and update Application Scene Manifest. Change the storyboard name in default configuration of Application Session Role. Also make sure one of your ViewController in storyboard is marked as is Initial View Controller

message sent to deallocated instance 0x600000147e80 error by clicking sub view event in container view OS X Swift

I am new in os x programming. I am using swift to developing my mac app. In my app home screen contains a Container view and some NSButtons. By clicking on the buttons the NSViewControllers (created in storyboard) appear on the ContainerView. This is done by the code below:
self.ContainerView.subviews.removeAll()
let myViewController = iR_DELEGATE.GoToPage("Questions",container: ContainerView)
self.ContainerView.addSubview(myViewController.view)
the GoToPage function code is:
func GoToPage(identify: String,container: NSView) -> NSViewController
{
let storyBoard = NSStoryboard(name: "Main", bundle: nil) as NSStoryboard
let myViewController = storyBoard.instantiateControllerWithIdentifier(identify) as! NSViewController
myViewController.view .setFrameSize(CGSize.init(width: container.frame.width, height: container.frame.height))
return myViewController
}
The problem is when I click on the button or select the table's view in the sub view controller that displayed in container view the app crash with error:
message sent to deallocated instance 0x600000147e80
I got this error by enable zombie objects.
Your crash is likely caused by the fact that the view controller is deallocated almost immediately after you created it.
A view controller holds a reference to its view, but not the other way around. When you add myViewController.view as a subview, it is retained and displayed. In the meantime, myViewController itself is not retained by anything, so it is removed from memory after the variable is last used.
You probably have your view controller as target to button's action. When you tap the button, it wants to send the action to the view controller, but it has been already deallocated, and it crashes.
To solve it, you need to keep the reference to myViewController to keep it from being deallocated earlier than needed. Either just store it in a variable, or consider using child view controllers for that purpose: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSViewController_Class/#//apple_ref/doc/uid/TP40005253-CH1-SW34

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.

Universal UIViewController

Please help me, I never made universal UIViewControllers with xib for iPhone/iPad. How I can create class with .m and .h files and _iphone.xib and _ipad.xib?
I was try to create xib manually and create outlets for view, but after pushing this controller I had uncaught error:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FullNewsViewController" nib but the view outlet was not set.
Thanks!
The problem, what I can see from the error you posted, is that you have not set the owner properties of the NIB correctly.
Your nib files does not seem to have the correct file's owner and thus can't set the view on the view controller.
Open the nib, and go to File's Owner in the left since of the screen. Set the Custom Class property to the class of your viewController.
The right click on the File's Owner again and drag the view property to your view.
You should follow Apple iOS App Programming Guide
Creating a Universal App
Here you will get some tips, how to create Universal Application.
Hope this will help you out.
REview this link may be helped you...
http://elusiveapps.com/blog/2011/10/converting-iphone-apps-to-univeral-ipad/
if the view controller can easily be used for both ....
MyViewController.h
MyViewController.m
MyViewController~ipad.xib
MyViewController~iphone.xib
Set the File's Owner in both the xib files to your UIViewController subclass and connect up the view + anything else you want connected.
When I init my view controller this is all that's required
MyViewController *viewController = [[MyViewController alloc] init];
// OR
MyViewController *viewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
The Apple docs for UIViewController state that if you provide a xib with the same name as the view controller it will be loaded. The ~ipad and ~iphone ensure that the correct xib is loaded.