What is the easiest way to custom NSTableView cell? - objective-c

I'm an iOS developer. I recently started my Mac project, but I found that unlike UITableViewCell, which is a subclass of UIView, the cell of NSTableView is NSCell, and I even can't create it in IB. I wonder if there are some easy ways to create subclass like NSTextFieldCell to put it into the NSTableView.
Any help would be appreciated! Thanks!

Have a look at the open source PXListView class on Github
This has a PXListViewCell that you can use as an example.

Related

Using Xcode and Interface Builder to create prototype views

I'm building an NSView that is a kind of collection view, but instead of a table or a grid it will be a graph editor (similar to quartz composer).
The problem I'm facing now is that I would like to load prototype views (for the nodes) from a xib file. Much like how UITableView and UICollectionView lets you design prototype cells in Interface Builder. But how are these objects then instantiated in multiple copies?
How does UITableViewController et. al. achieve this?
Solutions I have thought about:
Copy the view, but NSView does not support NSCopying "out of the box". This seems like the most logical so far. It also seems like the only option if you want to keep the NSView in a storyboard rather than a xib.
Load a nib and then send [nib instantiateNibWithOwner:self topLevelObjects:nil] multiple times.
NSView does support NSCoding but using that feels more like a hack.
Any more ideas?
I'm developing an Mac OS X app, not an iOS app.
You are correct, implementing NSCopying via NSCoding does feel like a hack, but it's prob'ly the quickest and most reliable way to code it.
Copy NSView in cocoa / objective-c "related copy/code answer"
You can put your view in the storyboard as a top level object of any given scene. Make sure you have an outlet to it from the controller/loader of that scene. You could likely pack it into an NSData and just hold on to that for each "copy" you want made/unarchived.

How to make a common UIViewController in storyboard iOS?

For example, I have a Question UIViewController. I can set up this question interface (add other views); after that, I want to click a button in the current interface to bring me to another Question interface.
Is there a workaround for this in storyboard? I can manage to achieve it by using xib files (NavigationController push). I hope I have made myself clear in this question.
It's like a common UIViewController, is there such concept with storyboards?
You need to use segues, a basic technique of storyboards.
See e.g. this help file / video.

Proper way to build custom UITableViewCell

I've been wondering about UITableView's and their cells for a while. UITableView is a very handy UIView subclass, but there is a lot of predetermined/forced content on a UITableViewCell. I was wondering what is the best way to create a custom UIView (which will end up being a UITableViewCell) for UITableView?
The cell has a certain style that has to be set and there are predetermined UILabels and accessory views that are completely immutable, other than their contents. I find this to be a big waste, but just giving the cell a custom content view (and background view, if one pleases) doesn't prevent or remove these processes or restore the memory.
Is there any way to create a lighter version of a UITableViewCell subclass? Or is there a way to use a UIView with a selection method instead (other than essentially creating a custom UITableView using UIScrollView)?
Any suggestions would be really appreciated.
There are a few methods:
From a XIB file:
ios steps to create custom UITableViewCell with xib file
http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/
Using Drawing:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318 (4th and 5th examples)
There doesn't seem to be an answer for this. UITableViewCells will always have UILabels and other views automatically added to them. I'm not sure if they are allocated before you set them, though. They may have custom setting / allocation methods.

Segue from tableView to UIImage

Hi I have a tableViewController with cells and I want it to segue to a picture when you click the cell. Considering the MVC design Pattern would it be recommended to create a new viewcontroller for the imageView or would the tableViewController be able to handle the information? Thanks
That sounds exactly what is described in the first example of this Apple guide and you can use a solution detailed in this SO question.

IOS custom button

I need a custom button like Instragram has in profile tab (the buttons that shows the number of photos and followers) but i don't know how to start to implement it.
Do i need to subclass UIButton or is there other way easier?
I think, the easiest approach would be to create a UIButtom with the typeUIButtonTypeCustom and add a subview to it with imageviews and labels as subviews to create the UI. Composition over inheritance.
Subclassing UIButton seems to me to be the obvious solution. I agree that subclassing UIViewController makes no sense. You don't use UIViewController objects to manipulate individual subviews within a view hierarchy controlled by another UIViewController object.
There are plenty of ways to do this, personally I would subclass UIViewController. Then you can edit its .xib in interface builder to make it look however you want and set different values programmatically. Then to detect a tap on the button you can just use the touchesBegan and touchesEnded (I'm pretty sure those aren't complete method names, check in the docs for more info on them) methods. If you want you could also set up a UITapGestureRecognizer for the view instead.