Month: August 2020

  • NSTableView custom highlight color with NSTableRowView

    Getting the right color when you select NSTableView’s row was frustrating for me since I didn’t know how to do it properly. But it is really simple, all you need to do is having a class inherit from NSTableRowView and override its method drawSelection(in dirtyRect: NSRect).

    import Foundation
    import Cocoa
    
    class MenuTableRowView: NSTableRowView {
    
        override func drawSelection(in dirtyRect: NSRect) {
            if self.selectionHighlightStyle != .none {
                let selectionRect = NSInsetRect(self.bounds, 2.5, 2.5)
                
                if let color = NSColor.init(named: NSColor.Name("menu_table_selection_color")) {
                    color.setFill()
                }
                
                let selectionPath = NSBezierPath.init(roundedRect: selectionRect, xRadius: 0, yRadius: 0)
                selectionPath.fill()
            }
        }
        
    }
    

    Change menu_table_selection_color value in Assets.xcassets file.

    Custom NSTableRowView

    Now go to your NSTableViewDelegate’s method add your custom NSTableRowView.

     func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
            return MenuTableRowView()
    }

    Here you can see how my Storyboard looks like. Table view highlight value must be regular.

    Spread the love
  • This app is not allowed to query for scheme fb in iOS

    This app is not allowed to query for scheme fb in iOS

    I wanted to open a Facebook Group page in the Facebook app on my iPhone but I was getting that error since I did not have any LSApplicationQueriesSchemes in my Info.plist file.

    This is the code

    let fbPage = "fb://profile/" + FB_GROUP_ID // Your Facebook group id e.g 8794808798015
    let fbURL = URL(string:fbPage)
    let canOpenURL = UIApplication.shared.canOpenURL(fbURL!)
    if (canOpenURL) {
        UIApplication.shared.open(fbURL!, completionHandler: nil)
    }

    After adding ‘fb’ in my scheme it solves the issue.

    My Info.plist file

    This app is not allowed to query for scheme
    Spread the love
  • Manually adding the rootViewController’s view to the view hierarchy is no longer supported. Please allow UIWindow to add the rootViewController’s view to the view hierarchy itself.

    Manually adding the rootViewController’s view to the view hierarchy is no longer supported. Please allow UIWindow to add the rootViewController’s view to the view hierarchy itself.

    I was having this issue when setting a new rootViewController from loginViewController , which was a rootViewController in the storyboard before the transition.

    SSAHomeViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"sIdHomeNavController"];
    
            [UIView transitionFromView:self.view
                                toView:homeViewController.view
                              duration:0.5
                               options:UIViewAnimationOptionTransitionFlipFromLeft
                            completion:^ (BOOL finished) {
                                if (finished) {
                                    [[[UIApplication sharedApplication] windows] firstObject].rootViewController = homeViewController;
                                }
                            }];

    I was not sure what was the problem. Since this works perfect on iOS 13 if I don’t use the [UIView transitionFromView] but I wanted to keep the animation effect, it looked good.

    I decided to made a simple trick, by using a dummy view. Which solved this problem.

    SSAHomeViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"sIdHomeNavController"];
    
            UIView *dummyView  = [[UIView alloc] initWithFrame:self.view.frame];
            dummyView.backgroundColor = [UIColor whiteColor];
            
            [UIView transitionFromView:self.view
                                toView:dummyView
                              duration:0.5
                               options:UIViewAnimationOptionTransitionFlipFromLeft
                            completion:^ (BOOL finished) {
                                if (finished) {
                                    [[[UIApplication sharedApplication] windows] firstObject].rootViewController = homeViewController;
                                }
                            }];

    instead of using homeViewController.view we use dummy view for the animation and white as its background, otherwise you will see black background between transitions.

    Spread the love