How to do a UIPickerView in tvOS? - uikit

UIPickerView is not available in tvOS.
How should I build an equivalent to it, knowing that the content of my Pickerview is dynamic and can include up to 10 elements.
Thank you for your answers.

Related

macOS cocoa TableView with variable Row-Height and custom cells

Situation
I want to create a News-Article table within a macOS Cocoa application. (see image below)
Each Cell consists of two labels. One for the header and one for the main-content.
Problem
Now the length of the news-bodies and the width of the whole TableView is variable. I want to have a variable height on each Row/Cell depending on the size of the labels in it.
What we tried
We tried the following:
We have a
TableView
-> TableColumn
-> Custom View
-> LabelHeader
-> LabelBody
The RowSizeStyle Property on TableView is set to "Automatic"
The cells are populated with a custom class. Basically we tried to implement this StackOverflow solution: Link to Solution -> which did not work for us.
(And many more solutions we could not get to run)
Question
Can anyone provide a working tutorial or solution for this problem? Or at least a promising approach?
PS I use XCode 9.4.1 and Swift 4 on macOS 10.13.5
Any help gladly appreciated, Thank you!
In a modern cocoa application you would use NSLayoutConstraint to implement dynamic height of a table view cell. The tricky part would be to get the height of the text that you can set the height of the constrain. This could be done being using an NSTextView instead of NSTextField and asking the layout manager for the current height.
NSRect usedRect = [[textView layoutManager] usedRectForTextContainer:[self textContainer]];
float newHeight = usedRect.size.height;
I used this in an objective c application some years ago so if you have further questions please let me know.

NSCollectionView or NSTableView automatic height adjustment of cells

In iOS you could use:
self.tableView.rowHeight = UITableViewAutomaticDimension
to achieve automatic height adjustment of cells.
Is there any way to achieve this behaviour in macOS with NSCollectionView or NSTableView?
Talking about NSTableView... As of El Capitan there was no easy way to do this. Not sure about new Sierra SDK.
From my experience, the most reliable way to regulate table row's height is to use NSTableViewDelegate method:
func tableView(tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
//Here you do some magic measuring actual content of the cell and returning heigh
}
The only positive thing is that some controls have: fittingSize property and can simplify process.
Also, dynamic content change will require you to call noteHeightOfRowsWithIndexesChanged method of table view, to cause that delegate method be called again where your code will recalculate new height.
With macOS 11 and newer, the situation is as follows:
NSTableView can now actually use auto layout to achieve automatic height adjustment of cells. You must properly configure your cell template(s) to use auto layout, and you must instruct the table to use auto layout (can also be done in the storyboard) for row height calculations:
tableView.usesAutomaticRowHeights = true
NSCollectionView is currently (2021) still behind in features compared to the iOS counterpart, and still doesn't support any tableview feature like automatic row heights.

xCode UIView with UITableView [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to make an app that has a calendar that takes up about 2/3 of the visible screen, and then under it are events that correspond to the selected day.
Basically it will look something like this: Calendar App
Should I use a UIView for the calendar, and then a UITableView for the corresponding information?
Also, I want the entire page to scroll when users scroll through the events in the tableView (not just the information in the table view). Would I need to wrap the entire page in a scrollView to accomplish this?
You don't need to have a UIScrollView. You can simply hide the calendar (with animation) when the table view scrolls to a certain point.
Another simpler solution is to put your calendar in the first table view cell, so it would scroll along with your events. So this one just requires one UITableView that fills up the whole screen.

Static UITableView not showing cells with subviews (UIButton, UISlider etc.) in Content View

I've run into a peculiar problem with Xcode. I have a custom UITableViewController that appears as a popover for a few settings in an iPad app. It's a static table view with just 3 cells in 2 sections. It looks fine in the Storyboard editor, but at runtime the cells with custom views (UILabels, UISlider, UIButton) do not show up at all, but those custom views do (in random places).
When I delete the custom elements from the cell or change the cell to anything but custom then they show up fine, even if the view (like basic for example) contains a label in its Content View. It's a lot clearer to see with the attached picture.
To solve this, I've created a completely empty cell below those with custom elements. It looks fine, but I can't interact with any elements. User Interaction is enabled for all elements, cells, and the entire table view. If you have any ideas how to solve that or how to get the cells working properly so I don't need the blank cell hack that'd be much appreciated!
I'm using Xcode 6 beta 7 on OS X Yosemite, programming in Swift.
Thanks in advance!
The question has been answered here Stack Overflow Setting up Auto Layout connections from the label to the Content View solves this issue.
It was a combination of the above link as well as this one that finally solved it.
I added the 4 constraints from each object (UIButton and UISlider) to all four sides of its cell's Content View (top, bottom, leading, trailing). Then, I had to check the "installed" checkbox for each constraint, which was not checked.
Thank you so much for your help, it's working great now!

Can you use Storyboards to set auto-layout constraints on the contentView of a CollectionViewCell, as to take advantage of self-sizing cells in iOS 8?

I'm using Xcode 6 beta 5 at the moment, eager to try out the cool self-sizing collection view cells functionality introduced in iOS 8. It was introduced in the WWDC 2014 session 226: "What's New In Table Views and Collection Views". Links:
https://developer.apple.com/videos/wwdc/2014/
http://asciiwwdc.com/2014/sessions/226
http://blog.indragie.com/
All you gotta do, they said, is that you have to set auto-layout constraints on the contentView of your collection view cell or implement sizeThatFits:. The former sounds easier, so I definitely want to use auto-layout.
When got into Storyboard editor (or IB) though, it appears that you you cannot access the contentView property of a prototype collection view cell. Is this true?
I did set a few constraints between a label (direct subview of the prototype cell) — I pinned its four edges to the cell's bounds itself, hoping that the label's intrinsicSize would provide the needed width for the cell. No avail: I verified that none of these pinning constraints were applied onto the contentView:
- (void)awakeFromNib
NSLog(#"%s... contentView.constrants == %#", sel_getName(_cmd), self.contentView.constraints);
}
... prints out...
awakeFromNib... contentView.constrants == (
)
... no matter what constraints I set in Storyboard.
Am I missing something or must I do this auto-layout in code?

Resources