2016-05-12 27 views
4

我有一個刪除按鈕刷卡時變成可見的功能,但我真的很喜歡在郵件應用程序,在那裏,如果你繼續刷卡,刪除按鈕將被用於什麼情況,刪除該項目。 我見過使用如何獲得刪除類似的iOS的原生郵件應用程序

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? 

很多關於執行項目的教程,但我想不出用什麼來使按鈕擴大到表格單元格的整個寬度。有什麼想法嗎?

A look at what I want to implement

編輯:我會滿足於僅僅禁止刷卡一次刪除鍵已經顯露,我不喜歡你如何刷卡表格單元格來查看潛在的背景。

回答

1

這是可能的使用UIScrollView分頁。

創建UIScrollView,它作爲一個子視圖添加到您的UITableViewCell (還應加上尺寸限制,使滾動視圖大小相同,因爲它的父範圍)

現在設置了滾動型驗證碼:

//set scroll view 
scrollview.delegate = self; 
scrollview.pagingEnabled = true; 
scrollview.showsHorizontalScrollIndicator = false; 
scrollview.showsVerticalScrollIndicator = false; 
scrollview.contentSize.width = scrollview.bounds.width * 2.0; 

//create delete swipe view 
let deleteButton = UIView(frame: CGRectMake(scrollview.bounds.width,0,scrollview.bounds.width * 2.0,scrollview.bounds.height)) 
deleteButton.backgroundColor = UIColor.redColor() 

let deleteLabel = UILabel(frame: CGRectMake(0,0,scrollview.bounds.width * 0.3,scrollview.bounds.height)) 
deleteLabel.textColor = UIColor.whiteColor() 
deleteLabel.text = "Delete" 
deleteLabel.contentMode = .Center 
deleteLabel.textAlignment = .Center 
deleteButton.addSubview(deleteLabel) 
scrollview.addSubview(deleteButton) 

現在委託函數:

func scrollViewDidEndDecelerating(scrollView: UIScrollView) { 
    if scrollView.contentOffset.x == 0{ 
     return; 
    } 

    let confirmDelete = UIAlertController(title: "Are you sure you want to delete?", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet) 
    confirmDelete.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Destructive, handler: { (_) -> Void in 
     //Delete confirmed 

    })) 

    confirmDelete.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (_) -> Void in 
     scrollView.contentOffset.x = 0; 
    })) 

    rootViewController.presentViewController(confirmDelete, animated: true, completion: nil); 
} 

這將創造下一個效果:

enter image description here

+0

如何在單元格中添加其他內容? –

相關問題