Not woking UIView ishidden after change UILabel text value in swift - ios

I want to change uilabel value and show uiview that has hide like a popup windows.
When I touch a button, that code print "setPopupView 0".
but doesn't show settingView.
and I touch a button again.
print "setPopupView 0" and show settingView.
so When "settingLabelValueUnit text" has changed not show settingView,
but when "settingLabelValueUnit text" has not changed show settingView.
(It means "settingLabelValue text" is same as input value)
I don't know why.
Anyone can help me?
Thank you
here is my swift code.
class ViewController: UIViewController {
#IBOutlet weak var workoutScrollView: UIScrollView!
#IBOutlet weak var settingView: UIView!
#IBOutlet weak var settingLabelValueUnit: UILabel!
#IBOutlet weak var imgSettingBGcal: UIImageView!
#IBOutlet weak var imgSettingBGdis: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.imgSettingBGcal.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(calSettingClick)))
self.imgSettingBGdis.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(disSettingClick)))
}
func calSettingClick(sender: UITapGestureRecognizer) {
setPopupView(0)
}
func disSettingClick(sender: UITapGestureRecognizer) {
setPopupView(1)
}
func showPopup (_ settype:Int) {
switch settype {
case 0:
print("setPopupView 0")
self.settingLabelValueUnit.text = "Set1"
self.workoutScrollView.isHidden = true
self.settingView.isHidden = false
case 1:
print("setPopupView 0")
self.settingLabelValueUnit.text = "Set2"
self.workoutScrollView.isHidden = true
self.settingView.isHidden = false
}
}
}

Related

How add gesture into the tableviewcell?

everyone!
I am trying to add gesture to a UIImageView into the TableViewCell.
When click on the ImageView - the color changes.
class StocksCellView: UITableViewCell {
#IBOutlet weak var logoImageView: UIImageView!
#IBOutlet weak var tickerLabel: UILabel!
#IBOutlet weak var favouriteImageView: UIImageView!{ didSet {
let panGesture = UITapGestureRecognizer(target: self,
action: #selector(gestureAction))
favouriteImageView.addGestureRecognizer(panGesture)
}
}
#IBOutlet weak var companyNameLabel: UILabel!
#IBOutlet weak var priceLabel: UILabel!
#IBOutlet weak var deltaLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
#objc func gestureAction() {
favouriteImageView.tintColor = UIColor.yellow
}
}
But nothing works.
If i change favouriteImageView.addGestureRecognizer(panGesture)
on addGestureRecognizer(panGesture)
Then, by clicking on the cell, the color will change.
But I want by clicking on the picture.
enter image description here
First of all you must check and change like below:
favouriteImageView.isUserInteractionEnabled = true

How implement "Next" and "Done" functions of UITextField on Swift4?

I have a formulary of login, with 3 fields and a button to login. I wants set a button in the keyboard do jump of UITextField to next when user ends write the content. Besides that, when user put text on last field, the button login is hidden behind keyboard! I tried choose the options on the attributes inspector, but I don't know how use this.
class ViewControllerAuthentication: UIViewController {
#IBOutlet weak var btEntrar: UIButton!
#IBOutlet weak var textPassword: UITextField!
#IBOutlet weak var textEmail: UITextField!
#IBOutlet weak var textURL: UITextField!
let alert = Alerta()
var url : String?
var email : String?
var password : String?
override func viewDidLoad() {
self.btEntrar.addTarget(self, action: #selector(clickEntrar), for: .touchUpInside)
}
#objc func clickEntrar(_ sender : UIButton) {
// Do anything
}
}
You can do it, using UITextFieldDelegate, like...
class ViewControllerAuthentication: UIViewController, UITextFieldDelegate {
#IBOutlet weak var textPassword: UITextField!
#IBOutlet weak var textEmail: UITextField!
#IBOutlet weak var textURL: UITextField!
override func viewDidLoad() {
textPassword.delegate = self
textEmail.delegate = self
textURL.delegate = self
textURL.returnKeyType = .next
textEmail.returnKeyType = .next
textPassword.returnKeyType = .default // or .done
}
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
switch textField {
case textURL:
textEmail.becomeFirstResponder()
case textEmail:
textPassword.becomeFirstResponder()
case textPassword:
textField.resignFirstResponder()
default:
textField.resignFirstResponder()
}
return true
}
}
I suggest IQKeyboardManager, if you don't want to handle each field manually.

UIScrollView is being reset when editing UITextField

I'm new in Swift 3, and I just notice that we need to scroll a view since the keyboard can go over the some widgets as we type in text fields, like in this video. Fixing UITextField-Keyboard Problems (Swift in Xcode).
However, I am having an unfortunate behaviour even before programmatically scrolling the view. My view keeps being reset to its initial position. I made a video showing this behaviour.
I can't find mentions for this problem. Would someone have a clue?
[EDITED]
Here is the widgets are structured
Here is my View Controller code:
import UIKit
import AVFoundation
class SignUpController: UIViewController, UITextFieldDelegate
{
#IBOutlet var scrollView: UIScrollView!
#IBOutlet var stackView: UIStackView!
#IBOutlet var usernameTextField: UITextField!
#IBOutlet var passwordTextField: UITextField!
#IBOutlet var confirmationTextField: UITextField!
#IBOutlet var emailTextField: UITextField!
#IBOutlet var phoneTextField: UITextField!
#IBOutlet var firstNameTextField: UITextField!
#IBOutlet var lastNameTextField: UITextField!
#IBOutlet var signUpButton: UIButton!
var keyboardHeigh:CGFloat!
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.scrollView.contentSize = self.stackView.frame.size
self.scrollView.contentSize.height += self.stackView.frame.minY + 20
}
override func viewDidLoad() {
super.viewDidLoad()
let textFields :[UITextField] =
[
usernameTextField,
passwordTextField,
confirmationTextField,
emailTextField,
phoneTextField,
firstNameTextField,
lastNameTextField,
]
for i in 0..<textFields.count
{
textFields[i].delegate = self
textFields[i].tag = i
}
NotificationCenter.default.addObserver(self,
selector: #selector(keyboardWillShow),
name: .UIKeyboardWillShow, object: nil)
}
func keyboardWillShow(notification: NSNotification)
{
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
{
keyboardHeigh = keyboardSize.height
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool
{
// Try to find next responder
if let nextField = textField.superview?.viewWithTag(textField.tag + 1) as? UITextField
{
nextField.becomeFirstResponder()
}
else
{
// Not found, so remove keyboard.
textField.resignFirstResponder()
}
return false
}
}
1.You can take UItableViewController with static cell,
2.Put textField inside cell.
3.Make selection for cell none.
4.Make separator none.
It will work fine.

How do i get the Id of text view with radio Buttons clicked

For the radioButtons I have used Class in the button and for the indicator to buttons i have used the labels.
These are My TextView
#IBOutlet weak var TextViewEveryNewMessage: UILabel!
#IBOutlet weak var TextViewWeekly: UILabel!
#IBOutlet weak var TextViewDaily: UILabel!
#IBOutlet weak var TextViewMonthly: UILabel!
These are my Radio Buttons
#IBOutlet weak var RadioBtnMonthly: SSRadioButton!
#IBOutlet weak var RadioBtnWeekly: SSRadioButton!
#IBOutlet weak var RadioBtnDefaultChecked: SSRadioButton!
#IBOutlet weak var RadioBtnDaily: SSRadioButton!
As soon as i press the ok button i need to save the checkedRadio Button text somewhere and i have done it like this.
#IBAction func OkButton(sender: UIButton) {
SwiftSpinner.show(kLoadingText)
if RadioBtnDefaultChecked.selected{
preferencesConditions.notificationFrequency = self.TextViewEveryNewMessage.text
}else if RadioBtnDaily.selected{
preferencesConditions.notificationFrequency = self.TextViewDaily.text
}else if RadioBtnWeekly.selected{
preferencesConditions.notificationFrequency =
self.TextViewWeekly.text
}else{
preferencesConditions.notificationFrequency = self.TextViewMonthly.text
}
Is this correct way i am doing.Or there are any other approach. Please suggest me.
Instead of assigning a value for preferencesConditions.notificationFrequency in OkButton(sender: UIButton), you should do it in each of the SSRadioButton buttons and that's by calling SSRadioButtonControllerDelegate - didSelectButton:
func didSelectButton(aButton: UIButton?) {
print(aButton)
if aButton === RadioBtnDefaultChecked {
preferencesConditions.notificationFrequency = self.TextViewEveryNewMessage.text
}else if aButton === RadioBtnDaily {
preferencesConditions.notificationFrequency = self.TextViewDaily.text
}else if aButton === RadioBtnWeekly {
preferencesConditions.notificationFrequency =
self.TextViewWeekly.text
}else{
preferencesConditions.notificationFrequency = self.TextViewMonthly.text
}
}
Don't forget to conform the delegate to the viewController:
var radioButtonController: SSRadioButtonsController?
override func viewDidLoad() {
radioButtonController = SSRadioButtonsController(buttons: RadioBtnDefaultChecked, RadioBtnDaily, RadioBtnWeekly)
radioButtonController!.delegate = self
radioButtonController!.shouldLetDeSelect = true
}
The IBAction should be like:
#IBAction func OkButton(sender: UIButton) {
SwiftSpinner.show(kLoadingText)
}
For more information, check SSRadioButtonsController.
Hope this helped.

UIActivityIndicator shows for a split second

I am trying to show an spinning activity indicator for my app when the user taps on a button before they are presented with the next view - it kind of works, I see it for a split second
#IBOutlet weak var myActivityIndicator: UIActivityIndicatorView!
#IBOutlet weak var eventsbtn: UIButton!
#IBOutlet weak var pubsbtn: UIButton!
override func viewWillAppear(animated: Bool) {
myActivityIndicator.stopAnimating()
myActivityIndicator.hidden = true
}
override func viewDidLoad() {
super.viewDidLoad()
eventsbtn.layer.cornerRadius = 8
pubsbtn.layer.cornerRadius = 8
}
#IBAction func getEvents(sender: AnyObject) {
myActivityIndicator.hidden = false
myActivityIndicator.startAnimating()
}
Refactor your code. You don't need to stop the activity indicator in viewWillAppear. You can hide it in viewDidLoad. Here's the code:
#IBOutlet weak var myActivityIndicator: UIActivityIndicatorView!
#IBOutlet weak var eventsbtn: UIButton!
#IBOutlet weak var pubsbtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
eventsbtn.layer.cornerRadius = 8
pubsbtn.layer.cornerRadius = 8
myActivityIndicator.hidden = true
}
#IBAction func getEvents(sender: AnyObject) {
myActivityIndicator.hidden = false
myActivityIndicator.startAnimating()
}
Make sure that the IBOutlet for the activity indicator and IBAction for getting events are correctly connected in Interface Builder.
I changed it and it doesn't work, until I go back in the navigation
#IBOutlet weak var myActivityIndicator: UIActivityIndicatorView!
#IBOutlet weak var eventsbtn: UIButton!
#IBOutlet weak var pubsbtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
myActivityIndicator.stopAnimating()
myActivityIndicator.hidden = true
eventsbtn.layer.cornerRadius = 8
pubsbtn.layer.cornerRadius = 8
}
#IBAction func getEvents(sender: AnyObject) {
myActivityIndicator.hidden = false
myActivityIndicator.startAnimating()
}
viewDidAppear is probably a more appropriate place to stop the animation and hide the spinner.

Resources