In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use the swift table control. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The details are as follows
1. Effect drawing
A, ViewController inherits not only from UIViewController, but also from UITableViewDelegate,UITableViewDataSource.
B. there are three ways to re-implement UITableView by yourself. They are: numberOfSectionInTableView (table:UITableView), tableView (table:UITableView, numberOfRowsInSetion section:Int), tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
3. The version of Xcode I use: 7.2,
4. Complete source code
Import UIKitclass ViewController: UIViewController, UITableViewDelegate,UITableViewDataSource {let ctrlName = ["button", "label", "text box", "prompt box", "switch button"]; var tableView:UITableView?; override func loadView () {super.loadView () } override func viewDidLoad () {super.viewDidLoad () / / create the view tableView = UITableView (frame: view.frame, style: .Plain); tableViewroom.dataSource = self; tableViewroom.delegate = self; tableView?.registerClass (UITableViewCell.self, forCellReuseIdentifier: "SwiftCell"); view.addSubview (tableView!) / / create the tag let headerLabel = UILabel (frame: CGRectMake (0,0, view.bounds.size .width, 30)); / / set the tag attribute headerLabel.backgroundColor = UIColor.blackColor (); headerLabel.textColor = UIColor.whiteColor (); headerLabel.numberOfLines = 0; headerLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping HeaderLabel.text = "Common UIKIt controls"; headerLabel.font = UIFont.italicSystemFontOfSize (20); / / add the label tableViewview. TableHeaderView = headerLabel;} / set the partition func numberOfSectionsInTableView (tableView: UITableView)-> Int {return 1 } / / return the number of table rows func tableView (tableView: UITableView, numberOfRowsInSection section: Int)-> Int {return ctrlName.count } / / create cell display content, (create cells specified by indexPath) func tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)-> UITableViewCell {/ in order to improve table display performance, reuse let identify = "SwiftCell" for the created cells / / cells of the same form are reused, and let cell = tableView.dequeueReusableCellWithIdentifier (identify, forIndexPath: indexPath) is registered at the time of declaration; cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator; cell.textLabel?.text = ctrlName [indexPath.row]; return cell } / / UITableViewDelegate method to handle the list item selection event func tableView (tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {tableView.deselectRowAtIndexPath (indexPath, animated: true); let itemString = ctrlName [indexPath.row]; / / create a prompt box let alertView = UIAlertController (title: "prompt", message: "you selected\ (itemString)", preferredStyle: .Alert) / / add button let alertAction = UIAlertAction (title: "OK", style: UIAlertActionStyle.Default, handler: {(action)-> Void in}); alertView.addAction (alertAction); presentViewController (alertView, animated:true, completion:nil);} override func didReceiveMemoryWarning () {super.didReceiveMemoryWarning () / / Dispose of any resources that can be recreated. }} this is the end of this article on "how to use swift Table controls". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.