跳到主要內容

iOS 左滑功能 Swipe

 

method 1 - commitEditingStyle

這個method一定要複寫才會有功能出現

 

method 2 - canEditRowAtIndexPath

決定是否要出現左滑功能(要先有method 1)

 

method 3 - editActionsForRowAtIndexPath

若有自定義的功能,就得複寫這個method,但得連系統預設的功能也要一併複寫

也就是說複寫後連Delete也不見了,要一併再實作出來!

 

Objective-C

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView==self.categoryTableView){
return YES;
}else{
return NO;
}
}

- (NSArray *)tableView:(UITableView *)tableView
editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"More" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// show UIActionSheet
}];
moreAction.backgroundColor = [UIColor greenColor];

UITableViewRowAction *flagAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Flag" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// flag the row
}];
flagAction.backgroundColor = [UIColor yellowColor];

return @[moreAction, flagAction];
}

 

參考︰

http://pablin.org/2014/09/25/uitableviewrowaction-introduction/

自定義的ACTION參考︰

https://gist.github.com/scheinem/e36835db07486e9f7e64

 

Swift︰

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
//把剛剛寫的都刪光光
println("commitEditingStyle")
}

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
var actions = Array<UITableViewRowAction>()

let gatewayJson = gatewayList[indexPath.row]
let isAllowed = gatewayJson["isAllowed"].stringValue
let gatewaySN = gatewayJson["gatewaySerialNo"].stringValue
let newMobileName = defaults.objectForKey("mobileName") as? String
let gatewayUUID = gatewayJson["gatewayUUID"].stringValue

if(isAllowed != "Y"){
var authAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "授權") { (action, indexPath) -> Void in

println("授權")

self.hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
self.hud!.mode = MBProgressHUDMode.Indeterminate
self.hud!.dimBackground = true;
self.hud!.labelText = "申請授權!"

self.model.requestAuthorization(gatewaySN, mobileName:newMobileName!, completionHandler: { (request, response, responseData, error) -> Void in

MBProgressHUD.hideHUDForView(self.view, animated: true)

if(error == nil){
let json = JSON(data: responseData!.dataUsingEncoding(NSUTF8StringEncoding)!)

if let resultCode:String = json["result"]["code"].string {
let message:String = json["result"]["message"].string!
if(resultCode=="200"){
//通知
var alert = UIAlertController(title: "Message", message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (alertAction) -> Void in
//重新整理
self.tableView.reloadData()
}))
self.presentViewController(alert, animated: true, completion: nil)

}else{
var alert = UIAlertController(title: "Message", message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}else{
println("Error: Respose is nil ! responseData: \(responseData)")
//錯誤通知,不導頁
var alert = UIAlertController(title: "Message", message: "\(responseData)", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}

}else{
println(error)
//錯誤通知,不導頁
var alert = UIAlertController(title: "Message", message: "\(error)", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}

})
}

authAction.backgroundColor = UIColor(red: 255/255, green: 166/255, blue: 51/255, alpha: 1)

actions.append(authAction)
}


//delete按鈕自己做
var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "刪除", handler: {
(action:UITableViewRowAction! , indexPath:NSIndexPath!) -> Void in

println("刪除")

self.hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
self.hud!.mode = MBProgressHUDMode.Indeterminate
self.hud!.dimBackground = true;
self.hud!.labelText = "刪除授權!"

self.model.removeAuthorization(gatewayUUID, completionHandler: { (request, response, responseData, error) -> Void in

MBProgressHUD.hideHUDForView(self.view, animated: true)

if(error == nil){
let json = JSON(data: responseData!.dataUsingEncoding(NSUTF8StringEncoding)!)

if let resultCode:String = json["result"]["code"].string {

let message:String = json["result"]["message"].string!

if(resultCode=="200"){
//通知
var alert = UIAlertController(title: "Message", message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (alertAction) -> Void in
//重新整理
self.tableView.reloadData()
}))
self.presentViewController(alert, animated: true, completion: nil)
}else{
var alert = UIAlertController(title: "Message", message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}else{
println("Error: Respose is nil ! responseData: \(responseData)")
var alert = UIAlertController(title: "Message", message: "\(responseData)", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}

}else{
println(error)
//錯誤通知,不導頁
var alert = UIAlertController(title: "Message", message: "\(error)", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
})
})

actions.append(deleteAction)

return actions
}

留言

這個網誌中的熱門文章

小米路由器 mini 刷機

這次會來刷機是因為要給 MOD 使用 但原本的 小米路由器 mini 沒支援 IPTV 不想再買一台路由器(已經有四台了XD,有3台是被淘汰的)   參考文章︰ 1.  ERIC的攝影世界 - 小米路由器mini 免USB打開SSH  ( 備份檔案 ) 2.  ERIC的攝影世界 - 小米路由器mini韌體刷openwrt PandoraBox韌體  ( 備份檔案 ) 3.  寫寫東西 分享心得 - 小米路由器mini 改韌體 可看中華電信MOD iptv功能開啟 刷機 刷rom 直通MOD 老毛子Padavan固件 華碩 RT-AC54U  ( 備份檔案 )   其實找了很多篇文章,大部份都教用官方的那招,但不知道為什麼我就是取不到SSH的密碼 https://d.miwifi.com/rom/ssh  這個一直導不到要的那頁… 所以後來是用了  ERIC的攝影世界 - 小米路由器mini 免USB打開SSH  的第二招  免USB打開SSH 步驟︰ 1. 手動更新韌體到小米路由器mini 穩定版 2.8.14 ( 備用檔案 ) 2. 然後按  ERIC的攝影世界 - 小米路由器mini 免USB打開SSH  的 1.2.3.4.5   2.1 登入  小米路由器mini控制台  後複制網址     http://192.168.31.1/cgi-bin/luci/;stok=521b849e00a11c5b6743aa275ba84ed8 /web/home#router   2.2 將下面的網址紅色部份換成自己的,然後再貼到Browser上     http://192.168.31.1/cgi-bin/luci/;stok=521b849e00a11c5b6743aa275ba84ed8 /api/xqsystem/set_name_password?oldPwd=路由器控制台管理密碼&newPwd=admin     順利的會得到  {"code":0}   2.3 將下面的網址紅色部份換成自己的,然後再貼到Browser上     http://192.168.31.1/cgi-bin/luci/;stok=521b849e00a11c5b6743aa275ba84ed8 /api/x...

隱私權政策-台股營收分析

非常歡迎您使用APP「台股營收分析」(以下簡稱APP),為了讓您能夠安心的使用APP的各項服務與資訊,特此向您說明APP的隱私權保護政策,以保障您的權益,請您詳閱下列內容: 一、隱私權保護政策的適用範圍 隱私權保護政策內容,包括APP如何處理在您使用APP服務時收集到的個人識別資料。隱私權保護政策不適用於APP以外的相關連結APP,也不適用於非APP所委託或參與管理的人員。 二、個人資料的蒐集、處理及利用方式 當您造訪APP或使用APP所提供之功能服務時,我們將視該服務功能性質,請您提供必要的個人資料,並在該特定目的範圍內處理及利用您的個人資料;非經您書面同意,APP不會將個人資料用於其他用途。 APP在您使用服務信箱、問卷調查等互動性功能時,會保留您所提供的姓名、電子郵件地址、聯絡方式及使用時間等。 於一般瀏覽時,伺服器會自行記錄相關行徑,包括您使用連線設備的IP位址、使用時間、使用的瀏覽器、瀏覽及點選資料記錄等,做為我們增進APP服務的參考依據,此記錄為內部應用,決不對外公佈。 為提供精確的服務,我們會將收集的問卷調查內容進行統計與分析,分析結果之統計數據或說明文字呈現,除供內部研究外,我們會視需要公佈統計數據及說明文字,但不涉及特定個人之資料。 三、資料之保護 APP主機均設有防火牆、防毒系統等相關的各項資訊安全設備及必要的安全防護措施,加以保護APP及您的個人資料採用嚴格的保護措施,只由經過授權的人員才能接觸您的個人資料,相關處理人員皆簽有保密合約,如有違反保密義務者,將會受到相關的法律處分。 如因業務需要有必要委託其他單位提供服務時,APP亦會嚴格要求其遵守保密義務,並且採取必要檢查程序以確定其將確實遵守。 四、APP對外的相關連結 APP的網頁提供其他APP的網路連結,您也可經由APP所提供的連結,點選進入其他APP。但該連結APP不適用APP的隱私權保護政策,您必須參考該連結APP中的隱私權保護政策。 五、與第三人共用個人資料之政策 APP絕不會提供、交換、出租或出售任何您的個人資料給其他個人、團體、私人企業或公務機關,但有法律依據或合約義務者,不在此限。 前項但書之情形包括不限於: 經由您書面同意。 法律明文規定。 為免除您生命、身體、自由或財產上之危險。 與公務機關或學術研究機構合作,基於公...

隱私權政策-台股評價分析

非常歡迎您使用APP「台股評價分析」(以下簡稱APP),為了讓您能夠安心的使用APP的各項服務與資訊,特此向您說明APP的隱私權保護政策,以保障您的權益,請您詳閱下列內容: 一、隱私權保護政策的適用範圍 隱私權保護政策內容,包括APP如何處理在您使用APP服務時收集到的個人識別資料。隱私權保護政策不適用於APP以外的相關連結APP,也不適用於非APP所委託或參與管理的人員。 二、個人資料的蒐集、處理及利用方式 當您造訪APP或使用APP所提供之功能服務時,我們將視該服務功能性質,請您提供必要的個人資料,並在該特定目的範圍內處理及利用您的個人資料;非經您書面同意,APP不會將個人資料用於其他用途。 APP在您使用服務信箱、問卷調查等互動性功能時,會保留您所提供的姓名、電子郵件地址、聯絡方式及使用時間等。 於一般瀏覽時,伺服器會自行記錄相關行徑,包括您使用連線設備的IP位址、使用時間、使用的瀏覽器、瀏覽及點選資料記錄等,做為我們增進APP服務的參考依據,此記錄為內部應用,決不對外公佈。 為提供精確的服務,我們會將收集的問卷調查內容進行統計與分析,分析結果之統計數據或說明文字呈現,除供內部研究外,我們會視需要公佈統計數據及說明文字,但不涉及特定個人之資料。 三、資料之保護 APP主機均設有防火牆、防毒系統等相關的各項資訊安全設備及必要的安全防護措施,加以保護APP及您的個人資料採用嚴格的保護措施,只由經過授權的人員才能接觸您的個人資料,相關處理人員皆簽有保密合約,如有違反保密義務者,將會受到相關的法律處分。 如因業務需要有必要委託其他單位提供服務時,APP亦會嚴格要求其遵守保密義務,並且採取必要檢查程序以確定其將確實遵守。 四、APP對外的相關連結 APP的網頁提供其他APP的網路連結,您也可經由APP所提供的連結,點選進入其他APP。但該連結APP不適用APP的隱私權保護政策,您必須參考該連結APP中的隱私權保護政策。 五、與第三人共用個人資料之政策 APP絕不會提供、交換、出租或出售任何您的個人資料給其他個人、團體、私人企業或公務機關,但有法律依據或合約義務者,不在此限。 前項但書之情形包括不限於: 經由您書面同意。 法律明文規定。 為免除您生命、身體、自由或財產上之危險。 與公務機關或學術研究機構合作,基於公共利益為統...