跳到主要內容

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

Mac上無蝦米的終級方案!

之前是用香草輸入法,是可以打出無蝦啦,只是有些字尾會多出一個空白,很是討厭 今天突然發現一個不錯的輸入法居然可以很正常的打出無蝦米,真是超感動的啦 一開始是看到這個網頁,是介紹『鼠鬚管 (Squirrel)』這個輸入法的 https://blog.yorkxin.org/posts/2013/12/10/use-boshiamy-in-squirrel/ 但他需要一個官方的iBus表格檔,我沒有…我有買android及iOS的說...   然後,在下面的的連結找到了 http://monkey413.blogspot.tw/2014/04/fcitx-rime.html 輸入法官網  http://rime.im/ 安裝完輸入法後,將網友提供的檔放入到『用戶設定』指到的位置   然後打開default.yaml 在schema_list選項中,加入 - schema: liur 重新部署(不確定是否一定要)   內部的選項不知怎麼按出來?… ==>操作說明  https://github.com/rime/home/wiki/UserGuide

[PS4 VR] 影片轉檔

怎麼用索尼PSVR看安卓VR 360° 3D視頻 => 將雙眼視頻改成單眼視頻,將格式改成MPEG-4,解析度1920*1080 ,60幀 15000kbps https://kknews.cc/tech/vme9a5l.html ============================================================== Wondershare Filmora:  8.0.0 for Mac 破解版下載 http://www.iphoneba.net/2563.html v8.2.0 http://www.zhinin.com/wondershare_filmora-mac.html ============================================================== for Littlstar http://docs.littlstar.com/plugins/servlet/mobile?contentId=2262863#content/view/2262863 Video Requirements H.264 High@5.1 or lower Max pixel width: 2560 Max frame rate: 60fps (最好是29.97) YUV420/NV12 color space 20Mbps bit rate or lower Audio Requirements Stereo Audio only AAC (Advanced Audio Coding) 320Kbps bit rate or lower Container Requirements File extensions: MP4, MOV No fragmented MP4 No DRM 15 min max duration 以上~ Littlstar不支援平面的3D格式,只支援180或360 而PSVR的媒體播放器不支援3D,只支援360 ============================================================== Make 3D Videos For PSVR Wat