override func viewDidLoad() {
super.viewDidLoad()
tableView.backgroundColor = .clearColor()
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath){
cell.backgroundColor = tableView.backgroundColor
cell.contentView.backgroundColor = tableView.backgroundColor
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) ->
[UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .Normal, title: "Sil") { action, index in
let alert = UIAlertController(title: "Delete Planet", message: "Are you sure you want to permanently delete sadf?", preferredStyle: .ActionSheet)
let DeleteAction = UIAlertAction(title: "Delete", style: .Destructive, handler: nil)
let CancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alert.addAction(DeleteAction)
alert.addAction(CancelAction)
// Support display in iPad
alert.popoverPresentationController?.sourceView = self.view
alert.popoverPresentationController?.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 1.0, 1.0)
self.presentViewController(alert, animated: true, completion: nil)
let favPredicate = NSPredicate(format: "beaconID == \(self.favoritesList[indexPath.row].beaconID)")
deleteFavoritesContent(favPredicate)
favoritesList.removeAtIndex(indexPath.row)
//tableView.reloadData()
}
delete.backgroundColor = UIColor.redColor()
return [delete]
}
table a tıklayıp controller buttonuna tıkla. sonra custom class dan viewcontroller i tanımla.
table i main.storyboard dan controller a sağ click ile bağla. hem datasource hem delegate e.
sınıfa UITableViewDelegate, UITableViewDataSource eklenir.
var isimler = ["korhan", "abdullah", "ahmet", "ahmet", "ayşe"];
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
cell.textLabel?.text = isimler[indexPath.row]
return cell
}
Pull to refresh is built in iOS. You could do this in swift like
var refreshControl:UIRefreshControl!
override func viewDidLoad()
{
super.viewDidLoad()
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refreshControl)
}
func refresh(sender:AnyObject)
{
// Code to refresh table view
}
At some point you could end refreshing.
self.refreshControl.endRefreshing()
1- xib içine UITableViewCell atıp düzenle.
2- custom tableviewcell class oluştur bağla
3- kullanılan tableview classlarda aşağıdaki kod ile aktif et.
let yourNibName = UINib(nibName: "tableCell", bundle: nil)
tableView.registerNib(yourNibName, forCellReuseIdentifier: "cell")
new controlview oluşturulur ve içine tableview atırlır. sonra table view in ayarlarında tableview de
prototype cells = 1 yapılır.