I am working with my first tabbed application in xcode. I am just testing with some stuff since I'm relatively new to programming. I am just using the 2 views already put into the template. I am putting a slider into the first view and am going to attach it to a text box with numbers. But that isn't the problem! This is probably really stupid and simple, but when i run the application just to see the stuff on the simulator, it is just showing a black screen. NO CLUE WHY! But its killing me and would love some help!
You are not suppose to make connections in AppDelegate. You should use a ViewController for each class. I.E. FirstViewController, SecondViewController. AppDelegate is usually only used for calling save/restore messages.
You are getting the error because the storyboard view is assuming you are assigning it to the correct view. When you create the storyboard say you named it TestApp. Then, you should have a few classes. TestAppDelegate, TestAppDelegateFirstViewController, TestAppDelegateSecondViewController. Or something along those lines. FirstViewController should connect to the first view on the tab view. The Second should attach to the second.
AppDelegate is almost never used for UI. I would suggest you find a book on the matter. I'll suggest "iOS Programming. The Big Nerd Ranch Guide". It helped me a lot when I started.
Photo Exmaple:
I did end up starting a new project. Weird that the black screen showed up.. not really sure why that error was popping up.. I'm not really that knowledgable about the different errors and bugs that a program can have yet! Getting closer though!
Related
I'm experiencing weird crash in NSOutlineView: when i click "collapse" button, app crashes immediately and even "exception breakpoint" doesn't help to see where the problem is.
I've tried to run app without debugger, and reproduced the problem. Once app crashed, i've got OSX crash window and was able to extract crash message from there:
The window has been marked as needing another Update Constraints in Window pass, but it has already had more Update Constraints in Window passes than there are views in the window
there also call stack, but it won't help since crash happening inside libsystem_c.dylib, so i'm not posting it here.
It seems there is something wrong going with auto layout. Absolutely have no idea about next steps. Please give me an advice!
Also, one more thing, that began only after update to OSX Mojave.
After hours of debugging and testing, i noticed that that message is caused by "infinite layout loop".
Different code, related to outline view was causing NSSplitView to layout. And delegate method - (CGFloat) splitView:(NSSplitView*)sender constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex has been called about 200 times prior to crash.
It's hard to catch this bcs it's not actually infinite recursion, so just debugger doesnt help a lot.
I just added simple code that helped me to identify the issue:
static int a = 0;
NSLog(#"Layout: %d", a++);
Hope my experience will help somebody else!
For anyone who is having the problem in Xcode 14 and macOS using SwiftUI:
I just had the same crash by hiding a view with an animation. My main view contains two views, one view contained an empty ScrollView, which didn't cause a problem by itself, but by changing it's size it crashed. Just adding a basic Text within the ScrollView solved my problem and the app doesn't crash anymore.
I updated my build to IOS 14 and Mac OS 20.15.6 and the error went away.
try turning off 'Use Auto Layout' checkbox in nib (in File Inspector tab).
May have to disable it for each and every view.
Also, unrelated, but Mojave forces you to use Core Animation.
Most of my nibs have 'set wants layer' turned off.
However, in one of my nibs I had a stray setWantsLayer checkbox checked.
when I unchecked it, the view (NSSearchField) drew properly
I am developing the Mac OS port of an iOS App and do face a problem with NSManagedObjectContexts when using NSArrayControllers in the Storyboard based Cocoa app.
It's kind of a follow-up question to:
Storyboard with TabViewController in OS X Application - Core Data Array Controllers in each scene?
I do have some ViewControllers presented like in a TabBarController, showing the same CoreData Entities. They are loaded through NSArrayControllers, that are hooked up with InterfaceBuilder.
From my existing knowledge, it was no problem to get the data on the screens. Even editing and saving to CoreData works.
But I realized, that every Storyboard scene got it's own instance of the NSArrayControllers and each its own NSManagedObjectContext.
When changing and saving the data on one screen, it is NOT updated on the other screens, that are all bound through the IB bindings and work in all other cases. They are just showing the data, they have loaded initially and are not updating automatically.
I think the problem is, that the changed data from contextA is not merged (or synced) to the other contexts of the other screens.
What is the best way of doing that? Should I use the NSManagedObjectContextDidSaveNotification for this?
That would mean, I would have to write much code, to manually start merging the changes from one context to all the other NSManagedContexts. Does smell really bad to me. I think there must be a much easier way, that I am not aware of and unable to find out about.
If you do have a hint for me, please just stick me in the right direction.
Thanks for that already.
Problem solved, I did a thumb error with Cocoa Bindings: I just dragged an object in the storyboard to every scene and set that to the AppDelegate. I just instantiated several AppDelegates with this, very bad idea! I corrected this, referencing the AppDelegate through properties on my ViewControllers and now it works as it should be. IB just has its little edges, where one has to be totally aware, about what is happening.
I am extremely new at Xcode. I am building an app that has a collection view in it. It looks great in the storyboard view, but nothing shows up when I run the simulator. I have images and labels in the cells. I have created a subclass for the cells and made my connections for the images and labels into the .h file. For right now I am just making a stub prototype (cells don't link to anything). If anyone can give me an answer or just suggest something to try than that would be great.
You're making a dynamic prototype - to actually show data, you need to read up on datasources and delegates.
If I were you, I would start with trying to make a simple UITableView app first. Google UITableView tutorial to get started.
After you're familiar with the above concepts, then would I suggest to go through a collection view tutorial - it's a relatively simple set of concepts when you get it, but you have to get it first :)
I'm a fan of Xcode's new storyboarding, but I'm annoyed it won't work on iOS4. I understand why it won't work, because it relies on new classes added to the iOS5 framework. However, it would be cool to be able to port a storyboard back to iOS4 somehow. A tool that outputted xib files for the individual stories, and code generation for segues.
If anyone knows of anyone else doing something in this area, I'd be interested in using it, since my app needs to support iOS4, but I'd like to move forward with Storyboarding. Can i have my cake and eat it too?
Nope you cant. Ended up gutting the storyboarding and going back to individual xibs.
I've been working today on adding a sheet to the main window of my application. After having trouble seperating the two (main view/controller and sheet view/controller), I've gone with just having both views in the same xib and both controlled by the main controller. Now that it appears when the beginSheet method is called, I've designed the form, and hooked it up to the IBOutlets/Actions on my controller.
This is where the problem is. With no bindings between the forms objects and the controller, it displays perfectly. But when I connect buttons to IBActions, and text fields/imageviews to IBOutlets I encounter some weird display problems. I'm talking buttons not displaying (but the actions being executed when clicking where they should be), borders of NSBox's not showing and textfields not taking any typed text and displaying (still blank) further off the viewable area of the panel.
I discovered that I could rectify this by resizing the panel a little, but that's not usable. I did get it working fine with 3 textfields and 3 buttons and just close/minimize enabled (not that they actually seem to do anything to a sheet), but now I've hooked an imageview up to the controller and the one of the buttons isn't displaying again.
Is this something to do with the number of outlets/actions I'm using (The actual main window doesn't actually have any extra ones) or is it IB being buggy or me doing something very wrong?
My first suspicion would be that there is an exception being thrown somewhere during drawing the sheet. In my experience, that's usually the case when you get half-drawn controls like you're describing. Check the debugger console in Xcode to see if any error messages are being printed out there. You can also add a breakpoint on objc_exception_throw to have the debugger stop when an exception is thrown, that might shed further light on where exactly the problem is coming from.
This issue went away when I reconstructed the sheet from scratch. I do not know what caused the issue, but if anyone has a similar problem I would suggest trying to reconstruct it in a new sheet.