I'm constructing my first App for IOS and I'm struggling to find a way to do a simple ScrollView using the Swift code on the XCode6, please can someone help me to find the solution?
My problem is that I don't know how to make the scrollview work in my code. I already putted the code as you can see below in the ViewController.swift and I was expecting to be able to select the Outlet "scroller" in the Main.storyboard for a ViewController, instead of this I'm receiving the error *"fatal error: Can't unwrap Optional.None (lldb)"* EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0)
I have some ViewController screens and in one of that I putted one ScrollView and I want to make it works using the Swift.
I'm stuck on this:
import UIKit
class ViewController: UIViewController {
@IBOutlet var scroller:UIScrollView
override func viewDidLoad() {
super.viewDidLoad()
scroller.scrollEnabled = true;
scroller.contentSize = CGSizeMake(320, 624);
// 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.
}
}
I think if someone can provide a simple example how to do a scrollview using swift it will solve my problem. Any help is appreciate.
Trying to do it in a old style I tried to do it using a .m and .h file:
ViewController.m
#import "Amigo-Bridging-Header.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 624)];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Amigo-Bridging-Header.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
IBOutlet UIScrollView *scroller;
}
@end
Cheers