Why is NSCollectionView on macOS 12 with Objective-C on Xcode 13 not working? - objective-c

I am following a personal learning path for macOS development, learning the basics of C and Objective-C before moving on to Swift (which I already know a bit, but felt the need to learn where all that came from). I am aware there are better, more modern and functional APIs, so please do not suggest learning that or SwiftUI. The point of this question is knowing what is not working in my example.
I closely followed this tutorial, whose source code can be downloaded from here. My code is available here, instead.
The first thing I noticed while following the tutorial is that Xcode (v 13.3.1 on macOS
12.3.1) doesn't add a Collection View Item and a View to the xib's workbench when dragging out a Collection View from the Object Library to the main window. I worked around it by manually adding a Collection View Item and a Custom View to design the UI as the tutorial showed. I triple-checked and connected all outlets as instructed then pressed Cmd-R to build and run. The app crashed, bringing me to main.m at the return NSApplicationMain(argc, argv); line with the following error:
I understand part of this error, but do not know how to "register one item nib or class", while dataSource is not covered in this tutorial.
Comparing with the source code I noticed that an extra outlet was added from the Collection View, connecting its itemPrototype to the CollectionViewItem. I did just that and, this time, Xcode refused to build throwing this error:
Do you know how to make this work? I would also appreciate any and every explanation on the first error.
Thank you for your patience and help.

NSOutlineView changed quite a bit in macOS 10.11 and isn't compatible with the tutorial. NSOutlineView can be used in legacy mode by choosing layout Content Array (Legacy) in IB.

Related

Confused with how to implement view controller for cocoa app

I'm very new to objective-c and cocoa(started today), I have experience with java and this just seems like a different world. I'm building an app with scene kit and OSRSerialPort(Have looked at the example code and don't understand how the controller is connected to the view). The goal of this is to take accelerometer data from a micro controller and making a visual representation of it with scene kit. I've tried to implement my controller in the same way as the example project in OSRSerialPort's github. Mine just doesn't seem to work. I'm just confused on why my project would don't receive input from the port but the example one receives it just fine when I feel as I've implemented it the correct way. I've attached the xCode project here.
Would love any help on this.
I'm building an app with scene kit and OSRSerialPort(Have looked at
the example code and don't understand how the controller is connected
to the view)
With Xcode, you can connect a Controller to a View without writing any code. When you use Xcode's Interface Builder(IB), almost non-readable xml data is inserted automatically into the .xib file for a window, which is the code that actually connects the two objects.
Then when your application starts, the .xib file is parsed, and the objects listed in the .xib file are created and the connections listed in the .xib file are setup.
I would guess that the connections you can't find are in the window's .xib file.
In fact, ORSSerialPort's README.md says this:
This application demonstrates that it is possible to setup and use a
serial port with ORSSerialPort without writing a lot of "glue" code.
Nearly all of the UI is implemented using Cocoa bindings.
without writing a lot of "glue" code means that instead of writing code the developers did a lot of dragging between objects in IB. And Cocoa bindings is a term of art, but you'll see that you have to understand other things first.
After figuring out how to download the project and open it locally in Xcode, I was able to look at MainMenu.xib in IB. Below is a screen shot of what MainMenu.xib looks like in IB, and on the right hand side there is a partial list of the connections for ORSSerialPortDemoController:
Those connections were established without writing any code.
I'm very new to objective-c and cocoa(started today)
Well, then put your current project aside, and learn the basics of how to use Xcode in Hello World style apps, then work your way up. As you progress in your learning, you will know when you are ready to go back to your current project.

iAds throw an error quickly (XCode 4.3.1, iOS5, Storyboard)

Trying to test iAds from XCode 4.3.1. Without thinking much of it, I started using a storyboard, however all the examples of iAds I find use the XIB file only.
http://www.techotopia.com/index.php/Integrating_iAds_into_an_iOS_5_iPhone_App#Displaying_the_Ad
http://www.youtube.com/watch?v=zkMhWPh6fzM
http://www.youtube.com/watch?v=hsjSCM9JJrM
Even the iAds Suite is built on XIB file.
I'm pretty new at ObjectiveC, so I may have overlooked something obvious. But is that normal that using these examples fail onto a storyboard?
I could post code, but honestly that's the same as the YouTube examples.
Add iAd.framework to your target

Why cant I see the 'UIViewController subclass' under Cocoa touch for ios/macos?

I'm a newbie, and plainly started with a sample code from the book 'Beginning-iOS-5-Games-Development'.
Everything seems quite straight-forward, but i cant see the UIViewController subclass under the Cocoa touch for both ios/macos...
Would this have anything to do with the fact that the example is trying to work with Universal device type.
My Xcode version is 4.3.2, and im trying out ios5...
thanks for your help..
user
You have to select Objective-C class, then click Next. On the next screen, you can specify that the class you are making is a subclass of UIViewController.

How do I use a RootViewController when making an app without a ViewController?

I am trying to make a simple app from a tutorial that does not have a viewController at all. All the code is in the AppDelegate. I am on xcode 4.2 and I am getting this error:
Applications are expected to have a root view controller at the end of application launch
I'm not sure how to deal with this. There are some blogs out there with fixes but none of them are working for me and I really would like to understand what is going on here. And, how to fix it.
I do have a view that contains some buttons and labels. But I have no "ViewController". The files contained in my project are: AppDelegate.h, AppDelegate.m, and Window.xib only. There is no ViewController.h, ViewController.m
** edit **
I ended up making the app from a 'view based application' instead and just moving all the logic from the app delegate to the view controller. So, I didn't really solve the problem per se. The app works now though. Thanks for the help
It's not possible to have an iOS app that doesn't have a view controller. You can always create a trivial view controller, i.e.,
[[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds].rootViewController =
[[[UIViewController alloc] init] autorelease];
It sounds like you're looking at an old tutorial. UIWindow got a rooViewController property in iOS4. I believe it became required in iOS5 to help keep controller hierarchies and view hierarchies in sync with the addition of custom container controllers (and to fix a corner case where replacing the "root controller" of a UIWindow could stop orientation changes from propagating). There was a WWDC presentation in 2011 that explained this in some detail. I think it was Session 102, Implementing UIViewController Containment.
At then end of the day, there's no good reason not to have a root view controller. Apple wants to be able to assume it's there in their APIs going forward. If the tutorial you're looking at doesn't account for that, it's broken.
While I agree that there may be workarounds, another question to address is: why do you want an app without a view? Even if it's designed to run in the background and present no visual interface, at least make a simple view showing the application name and version, a largeish icon and perhaps a status. This kind of idle screen uses very little system resources, especially when the app is backgrounded, but improves the overall experience of the app.
If you set your deployment target to 4.3 and run on the iPhone 4.3 simulator, you won't get the warning.
To install the iOS 4.3 simulator, go to Xcode > Preferences > Downloads.

iOS 4.3: Difficulty attaching graphic to an Image View

I am a relative novice who is teaching himself Objective-C on Xcode to develop some simple iPhone game apps. I have done some reading on this but fear I'm missing something basic and obvious.
I made a simple "Hello, World" and, based on opinions in various forums, I decided to do a Tic Tac Toe. I found a nice video and built a version based on that, which ran fine. However, my own interpretation is already running into trouble.
I'm using Xcode 4.0.2 on Snow Leopard. I chose a View-Based Application template and pulled a large image view onto the layout to hold a PNG called board. I put nine small image views on the large one to hold individual cells for X and O (and created some PNGs for the images). I just attached board.png to the big image view through IB so that works fine.
Next I tried to associate cell 1 with x.png by assigning it to a variable called ximg. This is all set up in the view controller's viewDidLoad method like so -- "ximg = [UIImage imageNamed:#"x.png"];". I then used the code "cell1.image = ximg;" -- also in viewDidLoad. X appeared on the board when I built and ran.
My next step was cell 2. I wanted to use a variable in a custom method this time, so I could change it in the future. I declared a method "- (void)setcell2" (bad camelCase, I know). I put the following method into my view controller implementation file:
-(void)setcell2 {
cell2.image = ximg;
}
I also added the following message to viewDidLoad -- "[self setcell2];"
As you'd guess, I was figuring that when the app loaded, viewDidLoad would send that message to setcell2, which would attach another X in the second box, but this didn't happen.
If someone could give me some idea of what I'm overlooking, I'd be gratified. Example code is appreciated but I can figure that out with time. This is not homework. Thanks for reading!
Most likely you haven't set your cell up properly in Interface Builder. Make sure you have connected the property to the outlet.