iOS 8 Swift: Cannot unhide/hide UIView on button click - xcode

This is driving me crazy. I am trying to un-hide a hidden UIView on button click but its not working. Here is the code
import UIKit
class DownloadViewController: UIViewController {
#IBOutlet var activityView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.activityView.hidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func downloadAction(sender: AnyObject) {
self.activityView.hidden = false
}
}
Please help me. This is driving me nuts, that its not doing such a simple thing.

Make sure that your outlet is connected to the correct button in Interface Builder, try connecting it again by ctrl-dragging from the button in IB to the #IBOutlet code.

This code works, are you getting an error or does the button not do anything?

Swift 3
import UIKit
class DownloadViewController: UIViewController {
#IBOutlet var activityView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.activityView.isHidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func downloadAction(sender: AnyObject) {
self.activityView.isHidden = false
}
}

Related

Xcode - control drag function not working

Beneath is my code,
Currently, it isn't working and allowing me to connect a button to my swift file (main storyboard). Also, the timer function isn't working, would this be to do with the function not working as well?
unsure on how to fix this, let me know if you need any other screen shots.
Any help will be appreciated.
Thanks
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var CounterLabel: UILabel!
var time = 30
var timer = Timer()
#IBAction func start(_ sender: UIButton)
{
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(ViewController.action), userInfo: nil, repeats: true)
}
func action()
{
time += 1
}
//GIFS
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.
}
}

UISlider error XCode 7 Swift 2

I'm trying to build a very simple app just to see how the UISlider works. I've seen several tutorials and followed them to the letter but nothing seems to work.
I keep getting this error exactly when I try to move the Slider in the simulator, after I've successfully built
This is my whole code. It's really simple but I can't understand why the Slider won't work.
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var noteBottomLabel: UILabel!
#IBOutlet weak var sliderNoteBottom: UISlider!
#IBAction func changedSliderNoteBottom(sender: AnyObject) {
var noteBottomValue = Int(sliderNoteBottom.value)
noteBottomLabel.text = "\(noteBottomValue)"
}
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.
}
Can you see any problems with this? I'm probably noobing out, but I've looked everywhere and can't find an explanation
import UIKit
import CoreFoundation
class ViewController2 : UIViewController {
override func viewDidLoad() {
super.viewDidLoad();
}
#IBOutlet weak var slider: UISlider!
#IBAction func slidervaluechanged(sender: UISlider) {
print(Int(slider.value))
}
}
I have tried your code just made the print of slider.value rather than putting it on label .
But I have used Xcode 7.3 , I don't think this should be problem with Xcode .Use the sender as UISlider when making an #IBAction that looks better . Brings up the value of 0 at bottom and 1 at top.

Use of unresolved identifier 'self'

I am working on a Mac OS X application with Swift.
This is my first time and I thought it would be the same as it is on iOS.
So I got this error (in the title) on this code:
import Cocoa
import AppKit
class LoginViewController: NSViewController {
#IBOutlet weak var emailTextField: NSTextField!
#IBOutlet weak var passwordTextField: NSSecureTextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidAppear() {
}
super.viewDidAppear()
if NSUserDefaults.standardUserDefaults().valueForKey("uid") != nil && CURRENT_USER!.authData != nil
{
self.logoutButton.hidden = false
}
}
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
func loginAction(sender: AnyObject)
{
let email = self.emailTextField.text
let password = self.passwordTextField.text
...
}
}
What do I have to write instead of self?
Using self is correct. Try using the property stringValue instead of text.
Here is the code that worked for me:
#IBOutlet weak var emailTextField: NSTextField!
#IBAction func sendTapped(sender: AnyObject) {
let email = self.emailTextField.stringValue
print(email)
}

What function do I use to call out the complete menu in CVCalendar?

I am trying to call the entire menu with Month title from Mozharovsky/CVCalendar but I'm not sure what function will call this out?
This is the current code I am using:
import UIKit
import CVCalendar
class ViewController: UIViewController, CVCalendarViewDelegate, CVCalendarMenuViewDelegate {
#IBOutlet weak var calendarView: CVCalendarView!
#IBOutlet weak var menuView: CVCalendarMenuView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.navigationController?.navigationBar
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
calendarView.commitCalendarViewUpdate()
menuView.commitMenuViewUpdate()
}
func presentationMode() -> CalendarMode {
return CalendarMode.MonthView
}
func firstWeekday() -> Weekday {
return Weekday.Sunday
}
}
This is the what is rendered when compiled:
If you want to see the month title also you need to create a UIlabel and UIlabel outlet as such:
#IBOutlet weak var monthLabel: UILabel!
I got this answer by copying the code from Mozharovsky/CVCalendar Demo ViewController.swift file

How to use gesture to move large image in a view using swift

I can able to do pinch zoom using pinch gesture using swift. But after image enlarges, i can't able view the which is out of view. (i.e)can't able to move image around the screen. Can any one help me?
My code:
#IBAction func scaleImage(sender: UIPinchGestureRecognizer) {
sender.view!.transform = CGAffineTransformScale(sender.view!.transform, sender.scale, sender.scale)
sender.scale = 1
}
I need to view full image after zooming it.
Add ScrollView and add image on scrollView
class ViewController:UIScrollViewDelegate{
#IBOutlet var imageView: UIImageView!
#IBOutlet var scroll: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
scroll.maximumZoomScale=4;
scroll.minimumZoomScale=1.0;
scroll.bounces=true;
scroll.bouncesZoom=true;
scroll.contentSize=CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
scroll.showsHorizontalScrollIndicator=true;
scroll.showsVerticalScrollIndicator=true;
scroll.delegate=self;//assigning delegate
self.scroll.addSubview(imageView);
self.view.addSubview(scroll);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func viewForZoomingInScrollView(_ scrollView: UIScrollView) -> UIView?
{
return self.imageView
}
}

Resources