Does anybody know why the ZoomingPDFViewer Apple Sample Code project no longer works? It was working prior to the iOS 10 release but now it keeps returning a unrecognized selector error when calling [PDFScrollView setPDFPage:].
It seems like the custom classes set in the storyboard are no longer being instantiated.
I had the same issue. It seems that the auto conversion to Swift 3 doesn't work well with IBs.
There are two options:
a) You can set the argument label--i.e.the parameter name to be shown externally--to _. For example,
#IBAction func setPDFPage(_ sender: AnyObject) {
// ...
}
b) You can remove the IBAction connection in the IB and re-set it. Notice instead of the previous setPDFPage(sender:) the connection will say setPDFPageWithSender(sender:) or something like that. (I didn't actually try it with the code in question, but writing from experience here.)
The same is true for segues.
Related
I want to use kind of SwiftUI-like functional style of configuring the UI, for example by providing [a global] method hide(view: UIView) instead of writing view.isHidden = true.
Now this works fine but for reverse logic I want to have the global method show() but within context of an UIViewController it conflicts with the class method show(sender: Any).
Is there any language trick I can you in order not to have to write MyAppName.show() each time I use it?
Your title is a bit inaccurate. You already know how to disambiguate it. The question is about how to do so without repeating the module name. Unfortunately, I don't think there's any such way.
I found out that Swift compiler seems to be overreacting, as one method has 2 arguments and my method has 1 argument. What's the reason to write "nearly matches" and breaking compilation is unclear to me.
However, I found the solution:
extension UIViewController{
func show(_ view: UIView) { view.isHidden = false }
}
I'm having trouble accessing and using the variable the value I got from a popover
First time ever asking a question on here and fairly new to programming so please be gentle. My program has a popup that displays a date for the user to select, and then that date is passed back to the main view controller. I tested this aspect to make sure the data was being passed back to the vc by getting the program to display the date in a label using callbacks and delegation (I tested both ways), and it worked fine, but what I'm trying to do is use that value taken from the popup, placing it into a variable, and using it for further calculations in other functions.
I tried to take change the protocol function have a return value from originally (value: String) -> (), to (value: String) -> (String)
but then realized this wouldn't work when I try to access that function from say the viewDidLoad function I don't have an input value
like if I did this inside of viewDidLoad
date = popupValueSelected(value: ???) // throws an error because it doesn't know about the delegate
This is my delegate protocol code:
protocol PopupDelegate {
func popupValueSelected(value:String)
}
Here is the code used in my main view controller to get the Data from the popover, which all works fine
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let popup = segue.destination as! DatePopupViewController
popup.delegate = self
}
func popupValueSelected(value: String) {
date = value // how to access this value from somewhere else??
}
All I want to do is use the value that I from the popover in another separate function. How would I pass that value somewhere else if I can't return it? I've sifted through answers on here and saw someone ask a similar question, but the first answer I saw was to use delegation, but no further explanation. I don't want to display that value or use it right away, I only want to use it for another calculation, that will be displayed when the user clicks a different button.
I'm sorry if this doesn't make sense as I'm having a difficult time explaining the issue, hence the throwaway account, though I feel like there's something so simple that I'm missing.
I appreciate all the feedback I can get!
Unless I’m missing something you seem to be 90% of the way there. You’ve got popupValueSelected getting a value. If you store the value off to a class level variable you can then use it later. Let me know if I’m not understanding your issue fully.
Any anyone explain the syntax in adding two or more textfields together in Swift 3 inside XCode 8. This is for a desktop application, not IOS. NSTextField Control.
I need precision to the tenth's place. So I guess a float will be necessary.
Furthermore, how can I do the adding automatically when the textbox is updated, so it is adding on the fly. So I do not have to put in a "Calculate" button. Do I need to do anything special to sanitize the fields to prevent alphas to be typed?
Not the most helpful group. Here's what I found out works. added NSTextFieldDelegate to the top View Class Controller like so
class View1Controller: NSViewController, NSTextFieldDelegate
Then: in my viewdidload
txtField.delegate = self
Then I could override the function:
override func controlTextDidChange(_ obj: Notification) { run some code here }
I am having difficulty implementing an action for an NSMenuItem in Swift. Normally, you implement the action like this in Objective-C:
- (void) asdf:(id)sender
This works perfectly fine, after setting up the action in the first responder like so:
However, after rewriting my view controller in Swift, the following new method doesn't seem to be called:
func asdf(sender: AnyObject?)
It doesn't seem to work, even though both the Obj-C and Swift versions are for the same view controller subclass.
In Swift 3.0 you'd define it as:
func asdf(_ sender: Any)
Why?
If you use _ you can drop parameter name when calling a function, so now you can call it like:
object.asdf(object)
Instead of:
object.asdf(sender: object)
Moreover, with Swift you'd use Any instead of AnyObject in this context. You can find more on differences between those here.
I thought the following would populate my home variable with my HomeViewController
var home = self.parentViewController!.parentViewController! as HomeViewController;
Instead I get the following compile error 'Use of undeclared type HomeViewController' although it definitely exists and appears in the auto complete popup.
Often XCode6 displays the wrong error message. Is this an instance variable? It may be that parentViewController isn't set at init time (the fact that it's an implicitly unwrapped optional strongly suggests this). If this is in a function, I'd do this in an if let statement to give us a better sense of what's going on. Something like:
if let homeVC = self.parentViewController?.parentViewController as? HomeViewController {
self.home = homeVC
}
This would give us at least a better opportunity to debug. Two !s in a row maybe means you're not being totally respectful of what those declarations are trying to tell you.
The cause of this error was actually coming from a bug in xcode 6 rather than any kind of syntax error. It was related to this: Xcode 6 Strange Bug: Unknown class in Interface Builder file
I was able to fix this by clearing the projects derived data and build and restarting my machine.
I had faced the same problem while doing an unwind segue and trying to downcast the sourceviewcontroller. I bang my head for more than 30mins and then I realized it was fairly simple and bit crazy, I had all my files except this viewcontroller added to the Tests target and after adding this viewcontroller to the Tests target, everything worked Tada!! I m saved.