Setting maximum height for NSScrollView inside NSMenuItem - xcode

i am currently working on a menu bar application for OS X. I want do display some data in a NSTableView within the menu. I already managed to set the view of the first NSMenuItem to my NSScrollView.
The problem is that i don't know how to set the maximum height for the NSScrollView. I want something similar to the Shazam or Adobe Creative Cloud app: A small menu with a TableView inside it that scrolls but doesn't fill the entire height of the screen.
Here is what i currently have:
The way it works now is that the menu automatically fills the entire screen depending on how much data i put into the TableView.
Here is a screenshot of the way the Shazam app does it:
They display lots of information inside the table but restricted the NScrollView to have a fixed height.
I don't think this is hard to do but i don't know where to look for the option.
Any help would be really appreciated :)
Regards,
Timo

I finally figured it out! I assigned the wrong view to the NSMenuItem.
Now i have two outlets inside my AppDelegate:
#IBOutlet weak var myMenuItem: NSMenuItem!
#IBOutlet weak var myScrollView: NSScrollView!
Inside applicationDidFinishLaunching() i assign the NSScrollView to the view property of the NSMenuItem:
func applicationDidFinishLaunching(aNotification: NSNotification) {
...
self.myMenuItem.view = myScrollView
...
}
The problem i used to have that i set the menu items view to the NSTableView directly, not to the NSScrollView. Everything works fine now.
Thats what the result is looking now:
Exactly what i wanted :)
Regards,
Timo

Related

How to #IBOutlet in the storyboard?

Watch question
I am new to iOS development. I got a project to maintain, the problem is that I can't find where in the storyboard belongs the variable. For example, in my ViewControl there is such a line
...
#IBOutlet weak var imgBottomFade: UIImageView!
...
So, I need to find this UI view in the storyboard, I open storyboard, but I see there are more than 10 screens each of them pretty sophisticated, and I start to click on each view on the screen and check the name (equal to imgBottomFade), one view by another, one screen by another... pretty annoying, I believe in XCode should be kind of way to find out where the UI view connects from Controller to Storyboard.
Let me know what I missed?
What you could do:
-open both code file and storyboard
-zoom out to view the whole storyboard (25% or smaller scale factor)
move mouse over the black dot in front of IBOutlet
-observe carefully in storyboard: you should see the UIImageView highlighted
or
-search for imgBottomFade in the search bar (at the very top left)
-you will find at the end of the list a reference to Main
-click it
-that will position the storyboard on the relevant VC
-expand view in the left panel of storyboard
-you should easily find imgBottomFade in the list of objects.
or
-search ViewControl VC in storyboard (just 10 to inspect)
-select it and expand its view object in the left panel of storyboard.
-you should find imgBottomFade in the list of objects.

NSWindow launching with wrong size after setting contentViewController to NSTabViewController

I have an Xcode project with an NSWindowController whose contentViewController was set to a subclass of NSViewController. I recently removed the NSViewController subclass from the storyboard and replaced the contentViewController with an NSTabViewController subclass.
Now, when I run the application, the NSWindow opens with a size of 500x500 instead of the size of the first tab. What's more, there is no view I can see in the storyboard that has a size of 500x500, and that size isn't being programmatically, either. The window itself is set to a different size, as is the view in the NSTabViewController's first NSViewController.
I'm assuming that there is some sort of constraint I have to set somewhere, but if there is, I don't know where/how to find it. Using Xcode 9.2 and High Sierra.
Programmatically setting the window's size to the correct size in windowDidLoad() works, but if I ever change the size of the view, I'll have to change that, as well, which will get old, quick.
Sorry if this is vague; I genuinely have no clue what kind of screenshot or code snippet would be helpful.
I recently ran into this frustrating problem as well.
There are a couple options to workaround this problem:
As you mentioned, set preferredContentSize in each of your custom view controllers that hold the tab's content to your desired size. This is inflexible but it does work.
// Swift
class FooViewController: ViewController {
override func viewWillAppear() {
super.viewWillAppear()
preferredContentSize = NSSize(width: 400, height: 280)
}
}
I found a hint to a better solution in this SO answer. You can add a subview (stackview, nsview, etc...) to the main view of the view controller that handles the tab's content (phew!) and then add constraints that pin it to each edge and add constraints that set the size.
Here's a screenshot of what it looks like in Interface Builder. I added a Stack View and then added 6 constraints.
Hope this helps.
Joshua's answer with setting the preferredContentSize did the trick, all kudos to him! One remark worth making is that since this is done exclusively for the parent tab view controller it's a good idea to subclass it and move this handling into tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) delegate method, which gets invoked when the tab is selected:
override func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
tabViewItem?.viewController?.preferredContentSize = tabViewItem?.view?.frame.size
// Alternatively: tabViewItem?.viewController?.preferredContentSize = tabViewItem?.view?.fittingSize
super.tabView(tabView, didSelect: tabViewItem)
}
This way the preferred content size is always up to date and you can worry not about manually refreshing it, assuming the view provides the correct frame size or fitting size, which is easily achieved with constraints.
This method also get's invoked after the window controller finishes loading and where the 500×500 gets initially set.
Setting the preferred content size in every tabbed view controller itself is not ideal: the same code is duplicated across multiple controllers and adds unnecessary noise if these controllers are reused else where.
I had a similar issue. I added a view controller with a container view as the window content and pointed the container view content to the tab view controller.

Add Table View footer in Storyboard

Does anyone know if you can add a Table View footer in Storyboard?
I was able to add a header, but I can't find a way to add a footer too.
I have a programatic footer right now using viewForFooterInSection:, but I want to put it in Storyboard instead.
EDIT:
I'm able to put a UIView in the Storyboard right here if I drag it on the UITableView.
And if I create an outlet with #IBOutlet weak var footerView: UIView! and set it to self.tableView.tableFooterView = footerView and set self.tableView.sectionFooterHeight = 200 I still can't get anything to show up.
oh, I had a totally same problem and struggle with it almost two hours.
I turned out that I had a code which made a tableView unnecessary separator line clear in viewDidLoad(). When I remove it, it worked file.
In short,
it can be possible that you have this code in viewDidLoad()
tableView.footerView = UIView.init()

Xcode Navigation Bar Goes under ScrollView?

Design mode everything is fine but in live Navigation Bar goes under the ScrollView How am I gonna solve this problem ? Please help
Again, without seeing any code at all it is hard to say, but I believe that the navigationBar isn't displaying at all. If you're presenting the UIViewController directly from another view, you're not instantiating the UINavigationController it is embedded in.
A solution would be to either create a segue in your storyboard from your presenting view to the UINavigationController, or add a storyboardId to the UINavigationController and instantiating as:
let nav = storyboard.instantiateViewControllerWithIdentifier("STORYBOARD_ID_HERE") as! UINavigationController
presentViewController(nav, animated: true, completion: nil)
If you can show some code on how the view is presented you'll receive better help, since it's impossible to know exactly what is wrong based on just one image.

detect scroll in horizontally uitableviewCell

I have UiTableView containing some data, and I want to scroll the UiTableViewCells horizontally to the left or right to show some UiButtons that act some action relatif to the content of the cell.
How Can I do this?
I'm thinking in creating custom cell, and putting a scrollView in it, May this did the trick?
There is a tutorial for this at http://idevrecipes.com/2011/04/14/how-does-the-twitter-iphone-app-implement-side-swiping-on-a-table/ with sample code. He is using a UISwipeGestureRecognizer to trigger an animation that pushes the cell off the screen.
You could use a swipe gesture recognizer attached to your cell.
You can add a UIScrollView to the contentView of a UITableViewCell. If you want to scroll the content using buttons, simply overlay the UIScrollView with buttons and make them call the various scrolling methods of UIScrollView.
Nested UIScrollView (UITableView inherits from UIScrollView) are quite clever about detecting touch conflicts and resolving the users intended gesture.
https://github.com/JonasGessner/JGScrollableTableViewCell might be what you're looking for. It implements this using a UIScrollView inside the cell (just like the iOS 7 mail app).
(Yes the answer is a bit late, but it's never too late! :P)

Resources