-
-
Save himanshu-benzatine/75fa44dc0e3f2752973a79984b182d70 to your computer and use it in GitHub Desktop.
in this i have one tableview with 2 header that are fix see this code i m working web service .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DriverViewController.swift | |
// Transport | |
// | |
// Created by Benzatine Infotech on 8/3/16. | |
// Copyright © 2016 Benzatine Infotech. All rights reserved. | |
// | |
import UIKit | |
class DriverViewController: UIViewController { | |
let actInd: UIActivityIndicatorView = UIActivityIndicatorView() | |
var refreshControl: UIRefreshControl! | |
var Select : Bool = false | |
var Driverlist : NSArray = NSArray() | |
var showSection : [AnyObject] = [true, true]; | |
var TotalSection : [AnyObject] = ["RECOMMONDED DRIVER", "OTHER DRIVER"]; | |
var firstSection : NSMutableArray = NSMutableArray() | |
var secondSection : NSMutableArray = NSMutableArray() | |
var selectedindex : Int = -1 | |
var DriverBookdata : NSMutableDictionary = NSMutableDictionary() | |
@IBOutlet var Backgroundimage: UIImageView! | |
@IBOutlet var HeaderView: UIView! | |
@IBOutlet var btnNewrideBook: UIButton! | |
@IBOutlet var Headertitle: UILabel! | |
@IBOutlet var drivertable: UITableView! | |
@IBAction func btn_Menu(sender: AnyObject) { | |
self.navigationController?.popViewControllerAnimated(true) | |
} | |
@IBAction func btn_process_Next(sender: AnyObject) { | |
self.callWebserviceForBOOKINGDATA() | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent | |
let lbl = UILabel() | |
Backgroundimage.image = APP_BACKGROUND | |
print(self.DriverBookdata) | |
self.callWebserviceForDriverList() | |
refreshControl = UIRefreshControl() | |
refreshControl.attributedTitle = NSAttributedString(string:"") | |
refreshControl.addTarget(self, action: #selector(DriverViewController.refresh(_:)), forControlEvents: UIControlEvents.ValueChanged) | |
self.drivertable.addSubview(refreshControl) | |
Headertitle.attributedText = lbl.spacingbetweencharacters("RIDER", spacing: 5.0, font: UIFont(name: "OpenSans-Bold", size: 17.0)!) | |
self.drivertable.tableFooterView = UIView() | |
// btnNewrideBook.titleLabel!.textAlignment = .Center | |
Headertitle.textColor = VIEW_HEADER_WHITE_COLOR | |
HeaderView.backgroundColor = BUTTON_SUBMIT_LIGHT_BLACK | |
btnNewrideBook.titleLabel?.textAlignment = NSTextAlignment.Center | |
// UIApplication.sharedApplication().statusBarStyle = .LightContent | |
} | |
func refresh(sender:AnyObject) { | |
self.callWebserviceForDriverList() | |
} | |
func numberOfSectionsInTableView(tableView: UITableView) -> Int { | |
return TotalSection.count | |
} | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
if section == 0 { | |
if ((showSection[section] as AnyObject! as! Bool!) == true) { | |
return firstSection.count | |
}else{ | |
return 0; | |
} | |
}else if section == 1{ | |
if ((showSection[section] as AnyObject! as! Bool!) == true) { | |
return secondSection.count | |
}else{ | |
return 0; | |
} | |
} | |
return 0; | |
} | |
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { | |
let frame: CGRect = tableView.frame | |
let iconimage: UIImageView = UIImageView(frame: CGRectMake(10, 5, 26, 26)) | |
iconimage.image = UIImage(named: "ic_header_driver.png") | |
let addButton: UIButton = UIButton(frame: CGRectMake(frame.size.width - 30, 5, 26, 26)) | |
if section == 0 { | |
if ((showSection[section] as AnyObject! as! Bool!) == true) { | |
addButton.setImage(UIImage(named: "ic_up.png"), forState: .Normal) | |
}else{ | |
addButton.setImage(UIImage(named: "ic_down.png"), forState: .Normal) | |
} | |
}else if section == 1{ | |
if ((showSection[section] as AnyObject! as! Bool!) == true) { | |
addButton.setImage(UIImage(named: "ic_up.png"), forState: .Normal) | |
}else{ | |
addButton.setImage(UIImage(named: "ic_down.png"), forState: .Normal) | |
} | |
} | |
addButton.tag = section + 1 | |
addButton.setTitleColor(UIColor.whiteColor(), forState: .Normal) | |
addButton.addTarget(self, action: #selector(self.sectionTapped), forControlEvents: .TouchDown) | |
let title: UILabel = UILabel(frame: CGRectMake(50, 3, 200, 30)) | |
title.text = TotalSection[section] as AnyObject! as! String! | |
title.textColor = UIColor.whiteColor() | |
title.font = UIFont(name: "OpenSans-Semibold", | |
size: 15.0) | |
let headerView: UIView = UIView(frame: CGRectMake(0, 0, frame.size.width, frame.size.height)) | |
headerView.addSubview(title) | |
headerView.addSubview(addButton) | |
headerView.addSubview(iconimage) | |
headerView.layer.backgroundColor = BUTTON_SUBMIT_LIGHT_BLACK.CGColor | |
return headerView | |
} | |
func sectionTapped(btn: UIButton) { | |
let index: NSIndexPath = NSIndexPath(forRow: 0, inSection: btn.tag - 1) | |
if ((self.showSection[index.section] as AnyObject! as! Bool!) == true) { | |
self.showSection[index.section] = false | |
} | |
else{ | |
self.showSection[index.section] = true | |
} | |
self.drivertable.reloadSections(NSIndexSet(index: index.section), withRowAnimation: UITableViewRowAnimation.Automatic) | |
} | |
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { | |
return 40 | |
} | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell | |
{ | |
let cell = tableView.dequeueReusableCellWithIdentifier("LabelCell", forIndexPath: indexPath) | |
let compnayname: UILabel = (cell.viewWithTag(6) as! UILabel) | |
let profileimage: UIImageView = (cell.viewWithTag(5) as! UIImageView) | |
let drivername: UILabel = (cell.viewWithTag(7) as! UILabel) | |
let check: UIButton = (cell.viewWithTag(8) as! UIButton) | |
let rating1: HCSStarRatingView = (cell.viewWithTag(9) as! HCSStarRatingView) | |
rating1.allowsHalfStars = true | |
rating1.userInteractionEnabled = false | |
profileimage.layer.masksToBounds = true | |
profileimage.layer.cornerRadius = profileimage.frame.size.height / 2 | |
if indexPath.section == 0 { | |
drivername.text = firstSection[indexPath.row].valueForKey("driver_name") as AnyObject! as! String! | |
let facebookProfileUrl = firstSection[indexPath.row].valueForKey("driver_image")! as AnyObject as! String | |
if facebookProfileUrl.isEmpty == true { | |
profileimage.image = UIImage.init(named: "ic_default_driver.png") | |
}else{ | |
let fbUrl = NSURL(string: facebookProfileUrl )! | |
profileimage.kf_setImageWithURL(fbUrl, placeholderImage: nil, | |
optionsInfo: [.Transition(ImageTransition.Fade(1))], | |
progressBlock: { receivedSize, totalSize in | |
}, | |
completionHandler: { image, error, cacheType, imageURL in | |
print("Finished") | |
}) | |
} | |
compnayname.text = firstSection[indexPath.row].valueForKey("company_name") as AnyObject! as! String! | |
let rat : NSNumber = firstSection[indexPath.row].valueForKey("driver_rating") as AnyObject! as! NSNumber! | |
rating1.value = CGFloat(rat) | |
Select = false | |
}else if indexPath.section == 1{ | |
Select = true | |
drivername.text = secondSection[indexPath.row].valueForKey("driver_name") as AnyObject! as! String! | |
let facebookProfileUrl = secondSection[indexPath.row].valueForKey("driver_image")! as AnyObject as! String | |
if facebookProfileUrl.isEmpty == true { | |
profileimage.image = UIImage.init(named: "ic_default_driver.png") | |
} | |
else{ | |
let fbUrl = NSURL(string: facebookProfileUrl )! | |
profileimage.kf_setImageWithURL(fbUrl, placeholderImage: nil, | |
optionsInfo: [.Transition(ImageTransition.Fade(1))], | |
progressBlock: { receivedSize, totalSize in | |
}, | |
completionHandler: { image, error, cacheType, imageURL in | |
print("Finished") | |
}) | |
} | |
compnayname.text = secondSection[indexPath.row].valueForKey("company_name") as AnyObject! as! String! | |
let rat : NSNumber = secondSection[indexPath.row].valueForKey("driver_rating") as AnyObject! as! NSNumber | |
rating1.value = CGFloat(rat) | |
} | |
drivername.textColor = LBL_WHITE | |
drivername.font = TEXTFIELD_FONT_14_MEDIUME | |
compnayname.textColor = LBL_TAB_TITLE_COLOR | |
compnayname.font = LABEL_FONT_17_MEDIUME | |
if selectedindex == indexPath.row { | |
check.setImage(UIImage(named: "ic_circle_sel.png"), forState: UIControlState.Normal) | |
}else{ | |
self.animateZoomforCellremove(cell) | |
check.setImage(UIImage(named: "ic_circle.png"), forState: UIControlState.Normal) | |
} | |
return cell | |
} | |
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
selectedindex = indexPath.row | |
print("You selected cell \(indexPath.item)") | |
self.animateZoomforCell(drivertable.cellForRowAtIndexPath(indexPath)!) | |
} | |
func animateZoomforCell(zoomCell: UITableViewCell) { | |
UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in | |
zoomCell.transform = CGAffineTransformMakeScale(1.1, 1.1) | |
}, completion: {(finished: Bool) -> Void in | |
self.drivertable.reloadData() | |
}) | |
} | |
func animateZoomforCellremove(zoomCell: UITableViewCell) { | |
UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in | |
zoomCell.transform = CGAffineTransformMakeScale(1.0, 1.0) | |
}, completion: {(finished: Bool) -> Void in | |
}) | |
} | |
// MARK: - Webservice method... | |
func callWebserviceForDriverList() -> Void { | |
HUD.show(.LabeledRotatingImage(image: UIImage(named: "progress"), title: nil, subtitle: "Login...")) | |
//fields ..rider_id, user_token, vehicle_type_id, pickup_date, pickup_time, dropoff_date, dropoff_time | |
let param : NSMutableDictionary = NSMutableDictionary() | |
let userInfo = UtilityHendler.getUserPlistData() | |
param.setValue(userInfo.valueForKey("rider_id"), forKey: "rider_id") | |
param.setValue(USER_TOKEN, forKey: "user_token") | |
let vehicletype : NSString = self.DriverBookdata.valueForKey("vehicle_type_id") as! String | |
param.setValue(vehicletype , forKey: "vehicle_type_id") | |
param.setValue(self.DriverBookdata.valueForKey("start_date"), forKey: "pickup_date") | |
param.setValue(self.DriverBookdata.valueForKey("start_time"), forKey: "pickup_time") | |
param.setValue(self.DriverBookdata.valueForKey("end_date"), forKey: "dropoff_date") | |
param.setValue(self.DriverBookdata.valueForKey("end_time"), forKey: "dropoff_time") | |
print(param) | |
let successed = {(responseObject: AnyObject) -> Void in | |
print(responseObject) | |
self.refreshControl.endRefreshing() | |
let code = responseObject["status_code"] as? Int | |
if code == 200{ | |
self.Driverlist = responseObject["driver_list"] as! NSArray | |
let driverListCount : Int = self.Driverlist.count | |
self.firstSection.removeAllObjects() | |
self.secondSection.removeAllObjects() | |
for i in 0..<driverListCount { | |
print(i) | |
if self.Driverlist.objectAtIndex(i).valueForKey("is_recommended") as! NSObject == 1 { | |
self.firstSection.addObject(self.Driverlist.objectAtIndex(i)) | |
} | |
else{ | |
self.secondSection.addObject(self.Driverlist.objectAtIndex(i)) | |
} | |
} | |
print(self.firstSection) | |
print(self.secondSection) | |
self.drivertable.reloadData() | |
HUD.flash(.Success, delay: 2.0) | |
}else{ | |
UtilityHendler.showAlertWithStatusCode(code!) | |
HUD.flash(.Error, delay: 2.0) | |
} | |
} | |
let failure = {(error: AnyObject) -> Void in | |
print(error) | |
HUD.flash(.Error, delay: 2.0) | |
} | |
ServiceHendler.callWebserviceToUploadImageWithParams(param as [NSObject : AnyObject], imgParams: nil, videoParms: nil, action: GET_DRIVER_LIST, success: successed, failure: failure) | |
} | |
// MARK: - Webservice method... | |
func callWebserviceForBOOKINGDATA() -> Void { | |
HUD.show(.LabeledRotatingImage(image: UIImage(named: "progress"), title: nil, subtitle: "Login...")) | |
//fields ..rider_id, user_token, event_id, driver_id, pickup_location, dropoff_location, pickup_date, pickup_time, dropoff_date, dropoff_time, pickup_lat, pickup_long, dropoff_lat, dropoff_long | |
let param : NSMutableDictionary = NSMutableDictionary() | |
let userInfo = UtilityHendler.getUserPlistData() | |
param.setValue(userInfo.valueForKey("rider_id"), forKey: "rider_id") | |
param.setValue(USER_TOKEN, forKey: "user_token") | |
param.setValue(self.DriverBookdata.valueForKey("event_id"), forKey: "event_id") | |
if Select == false { | |
//first selc | |
param.setValue(self.firstSection.objectAtIndex(selectedindex).valueForKey("driver_id"), forKey: "driver_id") | |
}else{ | |
//second selc | |
param.setValue(self.secondSection.objectAtIndex(selectedindex).valueForKey("driver_id"), forKey: "driver_id") | |
} | |
param.setValue(self.DriverBookdata.valueForKey("pickuplocation"), forKey: "pickup_location") | |
param.setValue(self.DriverBookdata.valueForKey("droplocation"), forKey: "dropoff_location") | |
param.setValue(self.DriverBookdata.valueForKey("start_date"), forKey: "pickup_date") | |
param.setValue(self.DriverBookdata.valueForKey("start_time"), forKey: "pickup_time") | |
param.setValue(self.DriverBookdata.valueForKey("end_date"), forKey: "dropoff_date") | |
param.setValue(self.DriverBookdata.valueForKey("end_time"), forKey: "dropoff_time") | |
param.setValue(self.DriverBookdata.valueForKey("pickuplocationlat"), forKey: "pickup_lat") | |
param.setValue(self.DriverBookdata.valueForKey("pickuplocationlog"), forKey: "pickup_long") | |
param.setValue(self.DriverBookdata.valueForKey("droplocationlat"), forKey: "dropoff_lat") | |
param.setValue(self.DriverBookdata.valueForKey("droplocationlog"), forKey: "dropoff_long") | |
print(param) | |
let successed = {(responseObject: AnyObject) -> Void in | |
print(responseObject) | |
let code = responseObject["status_code"] as? Int | |
if code == 200{ | |
let Bookingconfirmdata : NSMutableDictionary = responseObject.valueForKey("booking_info") as! NSMutableDictionary | |
print(Bookingconfirmdata) | |
HUD.flash(.Success, delay: 2.0) | |
let confirm: Bookingconfirmcontroller = (self.storyboard?.instantiateViewControllerWithIdentifier("Bookingconfirmcontroller"))! as! Bookingconfirmcontroller | |
confirm.bookingconfirm = Bookingconfirmdata | |
self.navigationController?.pushViewController(confirm, animated: true) | |
}else{ | |
UtilityHendler.showAlertWithStatusCode(code!) | |
HUD.flash(.Error, delay: 2.0) | |
} | |
} | |
let failure = {(error: AnyObject) -> Void in | |
print(error) | |
HUD.flash(.Error, delay: 2.0) | |
} | |
ServiceHendler.callWebserviceToUploadImageWithParams(param as [NSObject : AnyObject], imgParams: nil, videoParms: nil, action: BOOK_RIDER, success: successed, failure: failure) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment