custom hight of many cells

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let a = indexPath.row
if a < dataCurrentOrder.count {

return 136
} else if a == dataCurrentOrder.count {

return 270
}

return 136

}

delay

//===========================================================

typealias dispatch_cancelable_closure = (cancel : Bool) -> Void

func delay(time:NSTimeInterval, closure:()->Void) -> dispatch_cancelable_closure? {

func dispatch_later(clsr:()->Void) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(time * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), clsr)
}

Sending json array via Alamofire

let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

let values = ["06786984572365", "06644857247565", "06649998782227"]

request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(values, options: [])

cache Image with Kingfisher

https://github.com/onevcat/Kingfisher

import Kingfisher

class DownloadImage {

class func downloadImages(URL: String) -> UIImage! {

let image = NSData(contentsOfURL: NSURL(string: URL)!)
//print(image)
return UIImage(data: image!)

Set hight tableView

func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
self.tableView.reloadData()
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width, 100)

}

call a func sender action

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

self.bt()

}

@IBAction func bt(sender: AnyObject? = nil) {
print("Called Action")
}

}

custom UITableViewRowAction swift

override func layoutSubviews() {

super.layoutSubviews()

for subview in self.subviews {
NSLog("jfhsdjf=\(subview)")
for subview2 in subview.subviews {
NSLog("sdfasfsadf=\(subview2)")
if (String(subview2).rangeOfString("UITableViewCellActionButton") != nil) {
if let button = subview2 as? UIButton { button.setTitleColor(UIColor.redColor(), forState: .Normal) }
}
}
}

}

view in view

for view in segmentBarView.subviews {
if view.isKindOfClass(UIButton) {
(view as! UIButton).setTitleColor(UIColor.grayColor(), forState: .Normal)
}
}

if NSStringFromClass(view.dynamicType) == "iOrder.RAMAnimatedTabBarController" {
(view as! RAMAnimatedTabBarController).animationTabBarHidden(false)
self.navigationController?.navigationBarHidden = false
}

Change to URLSession due to deprecation of NSURLConnection iOS9

NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) {(response, data, error) in
to ==> let session:NSURLSession = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
_ = session.dataTaskWithRequest(urlRequest) {(data, response, error) in

switchScreen() with mainStoryboard

func switchScreen() {
let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let vc : NewBillVC = mainStoryboard.instantiateViewControllerWithIdentifier("NewBillVC") as! NewBillVC
self.presentViewController(vc, animated: true, completion: nil)
}

Pages

Subscribe to Trần Mạnh Hoàng RSS