How to show Storyboard UI using NSExtensionPrincipalClass for sharing extension - ios

I am implementing share extension functionality in iOS app. I am able to use "NSExtensionPrincipalClass" in share extension's Info.plist file. And I have added custom MyViewController i.e.
import UIKit
#objc(MyViewController)
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("My view loaded!!!!")
// Do any additional setup after loading the view.
}
}
I have created storyboard with "MyViewController" and it's sample UI.
How do I show UI from storyboard created for "MyViewController".?
When I run the app it prints "My view loaded!!!!" but not able to bind to UI i.e. UI is blank. How do I set UI for MyViewController from storyboard?

You need to replace NSExtensionPrincipalClass with NSExtensionMainStoryboard:
NSExtensionMainStoryboard
String - iOS, macOS. Specifies the name of the app extension’s main storyboard file, minus the .storyboard filename extension. This key, if used, must be placed as an immediate child of the NSExtension key.

Related

Materials Components MDCTextField added to the Xcode Interface Builder does not accept user input

I have used Cocoapods to integrate MaterialsComponents with a new Xcode Project and entered Xcode via the Workspace. I then created a very basic interface with one UITextField added to the main.storyboard. I did a build without errors and the simple interface allows me to enter data into the UITextField.
So then, copying Google's code sample in their lesson MDC-111, I converted the UITextField to an MDCTextField to see if the special Material Design handling of a Text Field works (i.e. the placeholder text moves up as I enter text). I had no build errors and the project correctly built in the simulator but does not allow text entry. Clicking on the field does not bring up the keyboard and does not accept text. I have tried changing the "User Interaction Enabled" from On to Off and back to On with no effect.`This is my Swift View Controller code:
import UIKit
import MaterialComponents
class ViewController: UIViewController, UITextFieldDelegate {
#IBOutlet weak var helloText: MDCTextField!
// MARK: Properties
var helloController: MDCTextInputControllerOutlined?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
helloController = MDCTextInputControllerOutlined(textInput: helloText)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I am closing this Question because kind folk on GitHub Materials Components site have solved it. For information, I had set a 'Height' constraint on the text field that was too small to allow the MDC behaviour to operate. Removing the constraint allowed the field to expand to full operational size.

Events from storyboard don't reach view controller

(Newbie question) after mucking around with renaming folders/modules, etc. I find that events are no longer triggered. Looking in the story board inspector, all events look to be wired properly.
But no events are triggered in the view controller.
How can this be debugged? Could it be something wrong with the module names, relative paths or anything like that.
Code snippets:
class ViewController: UIViewController, STBackgroundTaskDelegate, MeshViewDelegate, UIGestureRecognizerDelegate, AVCaptureVideoDataOutputSampleBufferDelegate {
viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
// ... more here...
}
Receiving method:
#IBAction func overlayTypeChangedWithSender(_ sender: AnyObject) {
NSLog("Overlay type changed")
showOverlay()
}
You may have forgotten to change the Custom Class in Storyboard or Xcode caches outdated data. Do the following:
Copy the NameOfViewController to the Custom Class field for your viewController in Storyboard.
Clean the project (Product -> Clean)
Clear Derived Data. Here is how.
Restart Xcode
Build & Run
Have you tried connecting another control in one of your problem classes? If you can do that, have a look at the connections inspector for the new control, and earlier ones in the same view - they SHOULD be connected to the same class (of course), but if they are not, you just need to remove the old connection and reconnect

Connecting IBOutlet in Newly Created .Swift File

I wrote some code in Swift for an iOS app in XCode (7.1.1) and I can't use the drag and drop in the interface builder for the outlet I want to connect. I tried to do it manually too but the outlet didn't show up in the reference collection when I tried to do it.
I did see this answer:
Can't connect IBOutlet in Interface Builder
But this appears to be for Objective-C/older versions of XCode. The way I have it right now is I have my main DataViewController.swift file and then I created a PhotoViewer.swift file (it's just an example so the code doesn't really matter it's pretty simple). I used the following code:
import Foundation
import UIKit
class PhotoViewer: UIViewController {
#IBOutlet weak var viewerButton: UIButton!
func loadPhotoUI() {
viewerButton.setTitle("View Photos", forState: .Normal)
}
}
The viewerButton does not show up as an option and when I open up the story board and try to Ctrl-Click and drag to the file on the right side, it doesn't let me drop it in.
If I try it on the DataViewController.swift file (the one that was there when I started the initial template), it still works.
I'm guessing I just need to change a setting on the new file but I can't seem to figure that out. I basically will be using the classes functions in the DataViewController like:
let photoClass = PhotoViewer()
self.photoClass.loadPhotoUI()
etc etc. I'm just wanting to keep everything super organized.
I'm obviously a bit of a noob at Swift so thanks for the help!
Your ViewController in your Storyboard needs to be linked to your Swift file.
You have to change the Class to "PhotoViewer" in your Identify Inspector in your Storyboard Viewcontroller:

customizing the share extension design in swift 2

I want to customize the design for share extension in swift 2. how can I do the customizations
class ShareViewController: SLComposeServiceViewController,NetworkSelectionViewControllerDelegate, PublishSelectionViewControllerDelegate{
var selectedNetworkName = "Default"
var selectedPublishName = "Select"
override func isContentValid() -> Bool {
// Do validation of contentText and/or NSExtensionContext attachments here
return true
}
You can create a custom Share Extension based on UIViewController:
Use the Xcode Share Template
The Xcode Share template provides default header and implementation
files for the principal view controller class (called
SharingViewController), an Info.plist file, and an interface file
(that is, a storyboard or xib file).
NOTE:
To provide a custom compose view instead of the standard one, deselect
“Use standard social compose interface” in the Xcode target-adding
pane. When this checkbox is deselected, the default
SharingViewController class is based on NSViewController or
UIViewController, depending on the platform you chose.

Xcode 6 interface builder does not show custom class

I have an error in my Xcode 6.3 interface builder.
When i create a new custom class and want to add it to interface builder custom class field. It is not available. I do use Swift as languag.
What I tried:
delete derived data
reinstall Xcode
cleand project
created new project
Class name is same as file name
Superclass and interface builder class are the same
Nothing worked out ;-( Any idea what it could be ?
I had the same issue and thought it as a bug. But it was my misunderstanding.
What actually happens is:
Custom Class drop down list shows only those custom classes which are subclasses of currently selected object's class.
For example, if we have imageview object in xib and after selecting it, when we see custom class drop down list, it'll show only custom classes inherited from (subclass of) UIImageView.
What I was doing wrong was looking for those custom classses which are subclasses of UIView.
In your case, it might be, not 100% sure, happening due to your TimerCVC is a subclass of UICollectionViewController instead of UIViewController.
TimerCVC is not a subclass of UIViewController
Press ctrl-n -> on the left panel choose iOS ->Source -> Cocoa Touch Class -> from the dropdown menu choose UIViewController -> And then fill the name field (automatically Xcode autocomplete with ViewController on the end).
It should look like this
import UIKit
class TimerViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

Resources