ios swift tableview

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet var myTable: UITableView?
var typeArray:NSArray!

override func viewDidLoad() {
    super.viewDidLoad()
    typeArray = ["onet", "two", "three", "four"];
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
{
return typeArray.count
}

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
    let identifier = "CellIdentifier"
    var cell :UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(identifier) as? UITableViewCell

    cell = UITableViewCell(style: .Default, reuseIdentifier: identifier)

    var string :String = typeArray[indexPath.row] as String
    cell!.textLabel.text = string
    return cell
}

 func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!)
 {
    var alert = UIAlertController(title: "Alert", message: "You have selected \(indexPath.row) Row ", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}
时间: 2024-08-24 22:42:38

ios swift tableview的相关文章

[IOS]swift自定义uicollectionviewcell

刚刚接触swift以及ios,不是很理解有的逻辑,导致某些问题.这里分享一下swift自定义uicollectionviewcell 首先我的viewcontroller不是直接继承uicollectionviewcontroller,而是添加的uicollectionview到我的storyboard, 然后再新建一个swift的文件,让这个swift继承uicollectionviewcell import Foundation class SVGCell :UICollectionView

iOS - Swift UISearchController仿微信搜索框

0x01.创建一个UISearchController 如果传入的searchController为nil,则表示搜索的结果在当前控制器中显示,现在我让它在searchVC中显示. // 创建searchResultVC let searchVC = UIViewController() // 设置背景颜色为红色 searchVC.view.backgroundColor = UIColor.red let searchController = UISearchController(search

iOS 在TableView的Cell之间设置空白间隔空间

1.设置section的数目,即是你有多少个cell - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; // in your case, there are 3 cells } 2.对于每个section返回一个cell - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)secti

iOS:Swift界面实例1, 简单界面

Apple推出了基于Objective-C的新语言Swift. 通过实例, 我们可以很好的感受这门新语言 注意事项: 在XCode6_Beta中, 如果有中文, IDE的自动补全功能就会失效, 所以开始调试的时候可以先用英文, 后面再用中文替代. 1. 新建iOS -> Single View Application. 2. 修改AppDelegate.swift文件 1 // 2 // AppDelegate.swift 3 // UIByCode_Swift_1_HelloWorld 4 /

[iOS] Create TableView & customize UITableViewCell

1. First artical, notice the last thing - Connecting the DataSource and Delegate: http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/ 2. Second Artical: https://medium.com/@musawiralishah/creating-custom-uitableviewcell-us

ios Swift 备忘录

Variables var myInt = 1 var myExplicitInt: Int = 1 // explicit type var x = 1, y = 2, z = 3 // declare multiple integers myExplicitInt = 2 // set to another integer value Constants let myInt = 1 myInt = 2 // compile-time error! Strings var myString =

ios Swift 资源池

Swift入门教程: http://www.cocoachina.com/applenews/devnews/2014/0604/8661.html Swift视频教程: http://www.cocoachina.com/bbs/read.php?tid=204280 Swift官方文档(PDF版): http://www.cocoachina.com/bbs/read.php?tid=204446 Swift官方文档(网页版): https://developer.apple.com/lib

ios Swift 之github

1. 软件类 a) 作者集合 http://nondot.org/sabre/ b) swift for facebook SWIFT是一个易于使用的,基于注解的Java来创建勤俭节约序列化类型和服务库. https://github.com/facebook/swift 2. 游戏类 a)FlappySwift https://github.com/fullstackio/FlappySwift b) 2048 https://github.com/austinzheng/swift-2048

iOS开发tableView去掉顶部上部空表区域

tableview中的第一个cell 里上部 有空白区域,大概64像素 在viewDidLoad中加入如下代码 self.automaticallyAdjustsScrollViewInsets = NO; 原文地址:iOS开发tableView去掉顶部上部空表区域