Monday, August 24, 2015

Class Form not found

Begin by installing this package through Composer. Edit your project's composer.json file to require laravelcollective/html.
"require": {
    "laravelcollective/html": "5.1.*"
}

Next, update Composer from the Terminal:

composer update


Next, add your new provider to the providers array of config/app.php:

  'providers' => [
    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
  ],

Finally, add two class aliases to the aliases array of config/app.php:

  'aliases' => [
    // ...
      'Form' => Collective\Html\FormFacade::class,
      'Html' => Collective\Html\HtmlFacade::class,
    // ...
  ],

Reminder to myself (note the comments)


        var frame: CGRect = CGRectMake(0, 0, 0, 0)
        self.backButton.hidden = true
        self.navigationController?.setNavigationBarHidden(true, animated: true)
        
        UIApplication.sharedApplication().statusBarHidden = true
        
        self.scrollView.canCancelContentTouches = true
        
        scrollView.delegate = self
        self.scrollView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
        let scrollViewHeight = self.scrollView.frame.height
        let scrollViewWidth = self.scrollView.frame.width
        // WASTING MEMORY. DO NOT "REDECLARE" THE VARIABLE THAT YOU CAN USE IT OUT OF THE BOX
        
        UIGraphicsBeginImageContext(self.view.frame.size)
        UIImage(named: "walkthroughBackground")?.drawInRect(self.scrollView.bounds)
        var backgroundImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        self.view.backgroundColor = UIColor(patternImage: backgroundImage)
        
        // WASTING MEMORY
        //declare all 6 steps as UIImage
//        let stepOneImage = UIImage(named: "step-1")
//        let stepTwoImage = UIImage(named: "step-2")
//        let stepThreeImage = UIImage(named: "step-3")
//        let stepFourImage = UIImage(named: "step-4")
//        let stepFiveImage = UIImage(named: "step-5")
//        let stepSixImage = UIImage(named: "step-6")
//        
//        self.images = [stepOneImage, stepTwoImage, stepThreeImage, stepFourImage, stepFiveImage, stepSixImage]
//        
//        let divideByTwo: CGFloat = 2.0
        
        let y = ((self.scrollView.frame.height - 325) / 2) - 20
        
        for index in 0..<6 {
//            var walkthroughImageView = UIImageView(image: images[index])
//            walkthroughImageView.contentMode = UIViewContentMode.ScaleAspectFit
            
            // DECLARATE A "STATIC" VARIABLE IN A LOOP IS HORRIBLE
            
//            let walkthroughImageViewWidth: CGFloat = 280
//            var walkthroughImageViewX = ((scrollViewWidth-walkthroughImageViewWidth)/divideByTwo) + (scrollViewWidth*CGFloat(index))
            
            
            //            println(walkthroughImageViewX)
            //
            //            if self.view.frame.size.height != 480 {
            //                walkthroughImageView.frame = CGRectMake((walkthroughImageViewX), 30, walkthroughImageViewWidth, 400)
            //                println(walkthroughImageView.frame)
            //            } else {
            //                walkthroughImageView.frame = CGRectMake((walkthroughImageViewX), 0, walkthroughImageViewWidth, 350)
            //                println(walkthroughImageView.frame)
            //            }
            //            
            
            var walkthroughImageView = UIImageView(image: UIImage(named: "step-\(index+1)"))
            walkthroughImageView.contentMode = UIViewContentMode.ScaleAspectFit
            walkthroughImageView.frame = CGRectMake(320 * CGFloat(index), y, 320, 325)

            self.scrollView.addSubview(walkthroughImageView)
            
        }
        
        self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.width * 6, self.scrollView.frame.height - 20)

        pageControl.addTarget(self, action: Selector("changePage:"), forControlEvents: UIControlEvents.ValueChanged)

Friday, August 21, 2015

Hide Tab Bar

You might have a table view in a tab bar controller, and in certain view you would like to hide the tab bar.

However, the scroll view's(table view)'s height/constraints have been defined when you enter the view controller, hence self.tabBarController?.tabBar.hidden = true will mess up your scrollable height

Add the following line to prepareforsegue when you enter that controller

segue.destinationViewController.hidesBottomBarWhenPushed = true

Monday, August 3, 2015

disable cell highlight/select color

We don't always want our SDK to "act smart" XD

In a table view cell there is always a highlight background color upon tap, if you don't like it simply disable selection style with


cell.selectionStyle = UITableViewCellSelectionStyle.None

How to call tableview controller method within cell class

I was removing cells from table view today with a button in the cell.

So after calling the remove function from the API, here comes the question, how do you refresh the table view's content.

Firstly, create a protocol method in your cell class

protocol BookingTableViewCellDelegate {
    func reloadTableViewData()

}

then 

var delegate: BookingTableViewCellDelegate?

in table view controller

    func reloadTableViewData() {
        println("reloading data")
        self.items.removeAllObjects()
        getBookings()
        self.myBookingTableView.reloadData()
    }

and add 

cell.delegate = self at cellForRowAtIndexPath

then finally, in your cell class:

self.delegate?.reloadTableViewData()