Xamarin.iOS UITableView programmatically hide separator lines - xamarin

I am creating a tableView in my ViewDidLoad and setting up a custom Source and Cell. That all works great. However the UITableView is displaying separator lines behind my custom view. I can comment out my code for the custom appearance so that the all that loads on screen is an empty UITableView and it still displays the separator lines even though I have set the separatorStyle = UITableViewCellSeparatorStyle.None
var table = new UITableView(View.Bounds);
table.SeparatorStyle = UITableViewCellSeparatorStyle.None;
table.SeparatorColor = UIColor.Clear;
table.TableFooterView = new UIView(CGRect.Empty);
Add(table);
I have also tried setting there color to clear and a blank footer to no avail.
Any help is greatly appreciated.

I know time to time Xamarin ios could be strange, but finally I was able to make it work.
You have to run this code in the ViewDidLayoutSubviews and it works
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
table.SeparatorStyle = UITableViewCellSeparatorStyle.None;
}

You need the following within your override the UITableViewController's ViewDidLoad method (I take it you have subclassed a ViewController for this purpose):
table.SeparatorStyle = UITableViewCellSeparatorStyle.None;
That should do the trick.
Regards,
John

Related

NSCollectionView inside NSTabViewController

I am facing a strange behavior of NSCollectionView inside a NSTabViewController.
I think that this issue appeared when I upgraded to High Sierra (not sure though).
My app has four tabs and each of them contains a collection view:
When I launch the app, the first tab is fine, problem is when I switch to other tabs. The collection view is not properly laid out:
As soon as I touch the window border the collection view reorganizes normally.
I tried to force the collection view to layout (.collectionView.layout()) without success.
Can anyone help me?
Thank you
This helped me out:
Subclassed the NSTabViewController
Added this:
override func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
let controller = tabViewItem?.viewController as? MyController
controller?.collectionView.frame = (controller?.view.frame)!
}
I ran into the same problem recently and the provided fix didn't work with my particular subview layout, but this did:
override func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
if let controller = tabViewItem?.viewController as? MyController,
let collectionView = controller.collectionView,
let contentSize = collectionView.collectionViewLayout?.collectionViewContentSize,
contentSize.height > collectionView.frame.size.height
{
collectionView.frame.size.height = contentSize.height
}
}
Maybe this is a more generally applicable solution.

nspopupbutton not behaving properly - showing Reversely

I am facing unique issue with nspopupbutton in one of my mac application.
I am using table view to load the filters, filters having different options, We can select the option from dropdown. As like I shown below.
My Issue is , After adding another filter (table view cell), My first cell dropdown text showing reversely. Please find the screenshot below.
Please share your thoughts , I really trapped in this issue.
Issue only in High Sierra MacOS.
Edit
I am creating custom cell in XIB as like below and binding the NS elements using tag
Code I used to load table view
public override nint GetRowCount (NSTableView tableView)
{
return appliedFilters.Count;
}
public override NSView GetViewForItem (NSTableView tableView, NSTableColumn tableColumn, nint row)
{
var vw = (FiltersCell)tableView.MakeView (parentVC.appliedFilters.ElementAt((int)row), this);
// Binddata is method I used to bind data in FIlterCell
vw.BindData (parentVC.appliedFilters [(int)row].ToString(), (int)row,parentVC);
return vw;
}
public override nfloat GetRowHeight (NSTableView tableView, nint row)
{
return 30;
}
macOS HS changes a number of layer based things, and if we are using the "old" NSCells somewhere it wouldn't surprise me they broke something.
You could try setting your parent view to layer based (WantsLayer = true or in IB) and see if that "fixes" things.
Multiple people have hit layer based regressions / issues in HS (not bugs in Xamarin.Mac).
From xamarin team

Use NSToolBar Outlet xcode 6 and Storyboard?

I am trying to add an outlet into my viewcontroller for a toolbar item in my window controller. I have tried playing around with first responder and bindings but have not been able to find any solutions.
A similar question that was answered provided some insight but no one has mentioned anything about IBOutlets other than still asking how to add them in the comments. The answer has been accepted so i am assuming no one will add to it.
How to use NSToolBar in Xcode 6 and Storyboard?
Incase my question is unclear at all, i would like to be able to add this to my storyboard program
#IBOutlet weak var Mytoolbar: NSToolbarItem!
func enabletoolbar()
{
Mytoolbar.action = "FunctionIn.ViewController.swift"
Mytoolbar.enabled = true
}
I found a decent workaround by adding IBOutlets to my custom NSWindow class and using the storyboard to connect my views to the IBOutlets. Then, I accessed these views from my NSViewController class by getting them from the custom NSWindow.
Basically you need to set the action and other properties to the toolbaritem but not in the toolbar. So try the same.
i ended up doing this in my view controller which seems to work
override func viewDidLayout() {
var x = self.view.window?.toolbar?.items[1].label
println(x)
if(self.view.window?.toolbar?.items[0].label! != "Check")
{
toobarediting()
}
println("didlay")
}
func toobarediting() {
self.view.window?.toolbar?.insertItemWithItemIdentifier("Check", atIndex: 0)
}
func toolbarcheck(functiontoset: Selector) {
var y = self.view.window?.toolbar?.items[0] as NSToolbarItem
y.action = functiontoset
if(functiontoset != nil)
{
y.enabled = true
}
}
It seems to allow me to make the tool bar button clickable/unclickable when ever i require it to change it just seems so much more bulky and error prone than
myitem.enable = fale
myitem.action = nil
is this really the best way for a storyboard based application in osx?
While connectiong IBActions works by using either the First Responder or by adding an "Object" to the scene, then changing its class to the window's view controller class, this doesn't help with IBOutlets and delegates that you'd like to point to the view controller.
Here's a work-around for that:
Add the Toolbar to the View Controller, not to its Window. That way, you can make all the IBOutlet connections in the View Controller Scene easily. I've done that for years and found no issues with it, even when using Tabs.
You'll have to assign the window's toolbar in code, then. E.g. like this:
#interface ViewController ()
#property (weak) IBOutlet NSToolbar *toolbar; // connect this in your storyboard to the Toolbar that you moved to the View Controller Scene
#end
- (void)viewWillAppear {
[super viewWillAppear];
self.view.window.toolbar = self.toolbar;
}

How to replace the deprecated method splitViewController:willHideViewController:withBarButtonItem:forPopoverController:

My standard implementation for this delegate method is the following. I just initialize the navigation button and save locally the button and the popover.
- (void) splitViewController: (UISplitViewController *) splitController
willHideViewController: (UIViewController *) viewController
withBarButtonItem: (UIBarButtonItem *) barButtonItem
forPopoverController: (UIPopoverController *) popoverController
{
// Set the button to open the PopOver
barButtonItem.title = viewController.title;
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
// Save the ref to the default left navigation button
_masterButton = barButtonItem;
// Save the ref to the PopOver
_masterPopOver = popoverController;
}
From iOS 8 this method is deprecated and the Apple documentation says:
Implement the splitViewController:willChangeToDisplayMode: method instead.
But the arguments of the new method has nothing to do with the deprecated method!
I guess I have to create a button and a popover myself?
Does somebody already made this re-coding to implement the current popup behaviour?
Thank you for your help
Take a look at displayModeButtonItem. It is very similar to barButtonItem from the deprecated method.
You can refactor your example into using the new splitViewController:willChangeToDisplayMode: method in the following way:
- (void)splitViewController:(UISplitViewController *)svc
willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode {
if (displayMode == UISplitViewControllerDisplayModePrimaryHidden) {
self.navigationItem.leftBarButtonItem = svc.displayModeButtonItem;
}
}
This is an extension to Alexander's answer. To cover Cihad's comment: the last line of code creates the leftBarButtonItem and makes it the blue "<" button that will open the master viewController.
I just commented out willHideViewController and willShowViewController from my detail viewController and cut and pasted Alexander's code. Worked first time.
Then I discovered that if I started the app in portrait it did not work until I went landscape and back to portrait. Obviously the method is not called until a change of orientation.
So I added this code in my viewDidLoad method of my detail viewController and it worked fine:
//Set up the splitview controller
if (self.splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryHidden) {
self.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;}
splitViewController is a property of your detail viewController that should be there for you to use.

Custom cell in Xcode 6 + Swift not displaying

I've searched a lot on the internet for a solution to this problem but I can't figure it out. I'm trying to create a custom cell in a table view.
I made a CustomCell.swift class to configure the labels I want in my custom cell, created it via storyboard (the first prototype cell in the tableview) and linked it with a identifier to the cellForRowAtIndexPath method
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cellIdentifier = "huisCell"
var cell: CustomCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? CustomCell
if cell == nil {
cell = CustomCell(style: UITableViewCellStyle.Value1, reuseIdentifier: cellIdentifier)
}
cell!.huisAdresLabel.text = "123"
cell!.huisDetailLabel.text = "456"
return cell
}
My CustomCell.swift code is like this:
class CustomCell: UITableViewCell {
#IBOutlet var huisAdresLabel: UILabel
#IBOutlet var huisDetailLabel: UILabel
}
It's very basic now, but I just want it to work because than I can expand the cell with more attributes and style it better.
Pictures via DropBox because I need 10 reputation to properly document my problem :)
https://www.dropbox.com/sh/5v9jb6cqp80knze/AAD5-yPR8-KoStQddkqKIbcUa
I hope someone can explain what I'm doing wrong.
Edit:
To clear up some things, before my try to make a custom cell, I got it working with the basic cells, with the one label on the left hand side. But when I tried to style the tableview and created a custom cell it won't work.
Also, when testing different solutions I came across the problem that de two labels in CustomCell.swift are nil. Even when I made a custom init and did like a
self.huisAdresLabel = UILabel()
it was still nil. in the code that I showed you it prints the following:
<UILabel: 0xb2aadc0; frame = (0 -21; 42 21); text = '123'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0xb2aa3a0>>
I resolved this issue by overriding the following function, setting the height of the cells manually:
override func tableView(tableView:UITableView!, heightForRowAtIndexPath indexPath:NSIndexPath)->CGFloat
{
return 44
}
Try using a xib file and adding your custom cell class to the
"Table View Cell" that you create in your xib file.
(Make sure you reconnect it to the outlets in your custom cell class ;)
This link may help.
http://www.weheartswift.com/swifting-around/
I had the same Problem, but after disabling the "Use Auto Layout" under the "File Inspector", it did work!! and the Custom Cells are displayed
Note: I made the Custom Cells in the Builder, not in Code. Using Xcode beta 3
Working w/ Custom table cells in Xcode 6 Beta-4's IB, I found they all rendered on top of each other and my non-Custom cell.
I fixed my problem by...
selecting the Custom cell in IB
selecting the Size inspector (Option-Command-5)
in the Table View Cell section
checking the Custom box
keeping the default-provided 44 Row Height
Quick workaround: disable Use Size Classes, but still don't know is it bug or feature :-) needs more investigation or man reading.

Resources