Swift, Pass data from popover controller to previous controller [closed] - ios

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
i want to fill text View in current controller from data existing in popover controller
with out reload data in current controller
can i do it ??

You can use custom delegate method to fill the value.
class PopupviewController {
weak var delegate: filleTextViewDelegate?
func calldelegate () {
delegate?.fillTextview(filledData)
}
}
protocol filleTextViewDelegate : class {
func fillTextview(filledData: String)
}
class CurrentViewController :filleTextViewDelegate {
func fillTextview(filledData: String) {
textView.text = filledData
}
}

Related

Get color from extension [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to easly store colors, like this:
extension UIColor {
class func color(hexString: UIColor) -> UIColor {
switch color {
case .light :
return UIColor.white
case .dark :
return UIColor.black
}
}
}
So I can do something like cell.myView.backgroundColor = UIColor.dark in a if statement. But the .light and .dark gives me this error:
Pattern cannot match values of type '(UIColor) -> UIColor'
Ant tips?
You could add extensions like this...
extension UIColor {
static let light = UIColor.white
static let dark = UIColor.black
}
And then access them like...
UIColor.light
And
UIColor.dark

UIImage.draw() function not working in viewDidLoad() callback [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
In the viewDidLoad() callback below, why does the image?.draw() function not work?
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let image = UIImage(named:"0")
image?.draw(in: CGRect(x: 0, y: 0, width: 100, height: 100))
}
// more code here
}
The method of a UIImage draws a image at a current graphic context. In the method viewDidLoad no a graphic context.
Move the calling of the drawing into draw method of some custom view.

Make a user access a view only after it has completed an action IOS Swift 3 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How can I make that an user can only access a View only after he/she has completed an action? For example, only access a view if the user has responded correctly to a question in a previous view in Swift 3 for IOS development
This is a very broad question, but the physics for poets version is you'd want to add some sort of target action method to monitor your textField. One the question is answered, the user can segue.
One approach would be to have a "next" button that's initially disabled and enabled once the question is correctly answered.
In FirstViewController, you could have an IBOutlet to a nextButton and a textField, like so:
#IBOutlet weak var textField: UITextField!
#IBOutlet weak var nextButton: UIButton!
You'd also control+drag a segue to SecondViewController
Then, in viewDidLoad, you could disable the button initially:
nextButton.isEnabled = false
You can't segue when the button is disabled. The moment it's enabled, you can segue by pressing it.
Then, you could have a method you create to monitor your textField for a correct answer:
// this is the method that monitors your textField
func textFieldDidChange(textField: UITextField) {
if textField.text != "42" {
nextButton.isEnabled = false
}
else {
nextButton.isEnabled = true
}
}
In viewDidLoad, you'd add a target action after your disable nextButton. Here's what viewDidLoad looks like:
override func viewDidLoad() {
super.viewDidLoad()
// this sets the button to disabled...
nextButton.isEnabled = false
// this monitors the textField for the correct answer
textField.addTarget(self, action: #selector(textFieldDidChange(textField:)), for: .editingChanged)
}
Here's a repo I created for you.

How to write a protocol to pass data backwards to UITableViewController? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
i was wondering how to write a protocol to pass data backwards to UITableViewController? If i write a normal protocol as one would write for UIViewController i get an error that "Type "TableViewController" does not conform to type protocol "PresentedViewControllerDelegate". "
Thanks for any help!
Only a protocol is not sufficient, you need also a delegate
Declare your protocol:
protocol PresentedViewControllerDelegate {
func method1(data:[String:AnyObject])
func method2(controller:PresentedViewController)
}
In the first method you pass a custom object (Dictionary),
in the second method the destination controller itself.
In the destination view controller PresentedViewController (the sender) create a delegate property:
weak var delegate : PresentedViewControllerDelegate?
and add code to call the methods
delegate?.method1(someDictionary)
delegate?.method2(self)
The optional chaining is very convenient, the methods aren't called if the delegate is nil.
In the source view controller (the receiver) add PresentedViewControllerDelegate to the declaration line, implement the required methods of the protocol and add a line in prepareForSegue to set the delegate.
let destinationController = segue.destinationController as! PresentedViewController
destinationController.delegate = self
Create your protocol, and have your custom UITableViewController subclass implement the protocol you created. Implement the required methods and properties in your controller and you're good to go.
Ex:
protocol YourProtocol
{
func method1(par1: String, par2: Int)
}
class YourTableViewController: UITableViewController, YourProtocol
{
//MARK:- YourProtocol Methods
func method1(par1: String, par2: Int)
{
//Receive your data through this method
//And Do your thing here
}
}
Your TableViewController have not implemented functions declared in the PresentedViewControllerDelegate protocol. Implement those functions and you'll be fine.
protocol PresentedViewControllerDelegate {
func somefunction(parameter: String)
func anotherfunction()
}
class Table: UITableViewController, PresentedViewControllerDelegate {
func somefunction(parameter: String) {
}
func anotherfunction() {
}
}

How to save text in TextField via Button click to a variable? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How to simply save written text via click of a "save" button into a variable "a" in Swift?
I tried this
class YourViewController: UIViewController {
#IBOutlet weak var textField: UITextField! //or UITextView
//lifecycle methods and so on ...
#IBAction func saveTextToVar(sender: UIButton) {
var text: NSString ?= textField.text
}
}
but while testing my app I always get an error.
http://www.bilder-upload.eu/upload/584458-1421163318.png
You need to define IBOutlet then connect it with your xib or storyboard.
After you need to define action and connect "Touch up inside" button action with your defined action.
Here the code
class YourViewController: UIViewController {
#IBOutlet weak var textField: UITextField! //or UITextView
//lifecycle methods and so on ...
#IBAction func saveTextToVar(sender: UIButton) {
var text: NSString ?= textField.text
}
}

Resources