Code Monkey home page Code Monkey logo

tableviewsample's Introduction

TableViewSample(iOS)

tableViewの使い方について。ViewControllerのコメント文参照

動作確認

git clone https://github.com/ha1fha1f/TableViewSample.git
cd TableViewSample
open tableSample.xcodeproj

TableViewを使うときの手順

TableViewを配置する

  1. StoryboardにTableViewを配置(TableViewControllerではない)

オリジナルのセルの枠組みを作る

  1. 設置したTableViewの上にTableViewCellを配置
  2. TableViewCellに必要なパーツを配置(UIImageView, UILabel等)

セル用のクラスを作る

  1. File -> NewFileとして、iOS用のSwiftファイルを選び、MyCell.swiftを追加(クラス名なのでなんでも良い)
  2. MyCell.swiftの内容を記述(3で配置したパーツに合わせて@IBOutletの変数を定義、MyCell.swift参照)
  3. IdentityInspecterからCustomClassをMyCellに設定(さっきの)
  4. AttributesInspecterからIdentiferを指定(今回はcell0)
  5. ConnectionsInspecterからTableCell上のパーツとMyCell.swift内のパーツを関連付け。

データソースプロトコルの実装

  1. UITableViewの@IBOutletをclass内に定義する(今回はtable、ViewController.swift参照)
  2. classの定義文の後ろに, UITableViewDataSource, UITableViewDelegateを追加(ViewController.swift参照)
  3. classの内部にセルの個数を返す関数
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{}

および、指定された行(列)のセルのインスタンスを返す関数

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {}

を記述する(ViewController.swift参照)

デリゲート、データソースをselfに設定する

  1. ViewController.swiftのviewDidLoadに
table.dataSource=self
table.delegate=self

を記述する

  1. Run!

tableviewsample's People

Contributors

ha1f avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.