import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate {
private var sampleTbl:UITableView!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:UITableViewCell=sampleTbl.dequeueReusableCell(withIdentifier: "identifier")!
cell.textLabel?.text="sample done"
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alert:UIAlertController=UIAlertController(title:"Test",message:"success",preferredStyle:UIAlertControllerStyle.actionSheet)
let cancel:UIAlertAction=UIAlertAction(title:"Cancel",style:UIAlertActionStyle.default,handler:nil)
alert.addAction(cancel)
self.present(alert, animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
sampleTbl=UITableView(frame:CGRect(x:20,y:50,width:300,height:300))
sampleTbl.delegate=self
sampleTbl.dataSource=self
sampleTbl.register(UITableViewCell.self, forCellReuseIdentifier: "identifier")
self.view.addSubview(sampleTbl)
let inptTxt:UITextField=UITextField(frame:CGRect(x:30,y:sampleTbl.frame.maxY+20,width:150,height:50))
inptTxt.backgroundColor=UIColor.purple
inptTxt.delegate=self
self.view.addSubview(inptTxt)
let butAdd:UIButton=UIButton(frame:CGRect(x:inptTxt.frame.origin.x,y:inptTxt.frame.maxY+10,width:200,height:100))
butAdd.setTitle("Add", for:.normal)
butAdd.setTitleColor(UIColor.red, for: .normal)
butAdd.backgroundColor=UIColor.yellow
butAdd.addTarget(self, action: #selector(ClickActio), for: .touchUpInside)
self.view.addSubview(butAdd)
// let activityView=UIActivityIndicatorView(activityIndicatorStyle:UIActivityIndicatorViewStyle.gray)
// activityView.center=self.view.center
// activityView.hidesWhenStopped=false
// activityView.startAnimating()
//// activityView.backgroundColor=UIColor(red:(100/255),green:(98/255),blue:(8/255),alpha:1.0)
// self.view .addSubview(activityView)
}
@objc func ClickActio(sender:UIButton!) {
print("add")
}
func textFieldDidEndEditing(_ textField: UITextField) {
textField.resignFirstResponder()
}
No comments:
Post a Comment