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.
}
}
Related
I'm not sure what I did wrong, but I tried to connect the outlet from my main storyboard to my new ViewControllerTableViewCell.swift that I just created.
I set the class to ViewControllerTableViewCell
It contains
import UIKit
internal class ViewControllerTableViewCell : UITableViewCell {
override internal func awakeFromNib()
override internal func setSelected(_ selected: Bool, animated: Bool)
}
Now, I open up my Main.storyboard and attempting to drag my image and label
I did't see the auto detect come up.
However, when I tried to drag those into my ViewController.swift, it works.
To make sure it is not XCode Caching issue. I also restart my XCode, and still face same issue.
I was hoping to see something like this
How do I check further to make this work again?
Good question. That's one of the disadvantages of using the interface building. But anyways, here's a solution:
Make sure that your custom tableView class, ViewControllerTableViewCell is assigned to your custom cell in your storyboard, like so:
Then, click on the automatic thing above, and see if you're viewing the cell class.
Try again now to have an outlet.
Also, CMD+B (building) helps the Xcode to correct some things.
You need to assign the custom tableCell class to the cell in IB
//
//
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.
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.
(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
After I have updated to Xcode to 7.3, I found Xcode can't create Xib file, when I create UIView class or UITableViewCell. Does anybody know the reason?
Very traditional way and existing with any XCode version.
Right click on left panel
Select new file
Select iOS
Select User Interface
Select Empty then next
Give file name.
That will create empty xib, now drag and drop UITableViewCell and give class name as you have given in .h and .m file or swift file name.
Swift class with UITableViewCell
import UIKit
class CustomCell: UITableViewCell {
#IBOutlet weak var lblName : UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
Yeah, this is a surprising issue.
First create a nib (e.g. ProfileHeaderView.xib) file from File -> New file.
Then create a .swift (e.g. ProfileHeaderView.swift) file and subclass it from UIView.
Last (but not the least of course), go to Identity Inspector of your .xib file and change the name of class to the name of the created .swift file (e.g. ProfileHeaderView.swift).
Hope that helps.
Make sure that you select Cocoa Touch Class in iOS section, rather than OSX's Cocoa Class. That lets you check option Also create XIB File. This works perfectly in Xcode 7.3 for ViewControllers, and any UIView subclasses (e. g. UITableViewCell, UICollectionViewCell)
EDIT: but not for UIView