一. 需求:
成都創新互聯公司一直在為企業提供服務,多年的磨煉,使我們在創意設計,成都全網營銷推廣到技術研發擁有了開發經驗。我們擅長傾聽企業需求,挖掘用戶對產品需求服務價值,為企業制作有用的創意設計體驗。核心團隊擁有超過10年以上行業經驗,涵蓋創意,策化,開發等專業領域,公司涉及領域有基礎互聯網服務服務器托管、重慶APP開發公司、手機移動建站、網頁設計、網絡整合營銷。
cell的側滑刪除默認只有一個刪除按鈕, 給側滑添加多個按鈕, '刪除', '置頂', '更多'.
二. 實現說明:
1) 我們在使用一些應用的時候,在滑動一些聯系人的某一行的時候,會出現刪除、置頂、更多等等的按鈕,在iOS8之前,我們都需要自己去實現。但是到了iOS8,系統已經寫好了,只需要一個代理方法和一個類就搞定了
2) iOS8的協議多了一個方法,返回值是數組的tableView:editActionsForRowAtIndexPath:方法,我們可以在方法內部寫好幾個按鈕,然后放到數組中返回,那些按鈕的類就是UITableViewRowAction
3) 在UITableViewRowAction類,我們可以設置按鈕的樣式、顯示的文字、背景色、和按鈕的事件(事件在Block中實現)
4) 在代理方法中,我們可以創建多個按鈕放到數組中返回,最先放入數組的按鈕顯示在最右側,最后放入的顯示在最左側
5) 注意:如果我們自己設定了一個或多個按鈕,系統自帶的刪除按鈕就消失了.
三. 代碼實現:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { // 添加一個'刪除'按鈕 UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"點擊了'刪除'"); // 1. 更新數據 // 2. 更新UI // [tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic]; }]; // 添加一個'置頂'按鈕 UITableViewRowAction *topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"置頂" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"點擊了'置頂'"); // 1. 更新數據 // 2. 更新UI //NSIndexPath *firstIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section]; //[tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath]; }]; topRowAction.backgroundColor = [UIColor blueColor]; // 添加一個'更多'按鈕 UITableViewRowAction *moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"點擊了'更多'"); [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle]; }]; moreRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; //將設置好的按鈕放到數組中返回 return @[deleteRowAction, topRowAction, moreRowAction]; }
相關閱讀:
詳解iOS開發中UITableview cell 頂部空白的多種設置方法
IOS中UITableView滾動到指定位置
以上所述是小編給大家介紹的Android中給UITableView的側滑刪除增加多個按鈕的實現方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對創新互聯網站的支持!
分享文章:iOS中給UITableView的側滑刪除增加多個按鈕的實現方法
文章路徑:http://m.kartarina.com/article40/pphceo.html
成都網站建設公司_創新互聯,為您提供、微信公眾號、響應式網站、品牌網站設計、小程序開發、營銷型網站建設
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯