LoginSignup
0
0

More than 5 years have passed since last update.

クラスとメソッド、プロパティと継承、、、、

Posted at

やはり、このクラスとプロパティと継承がよくわからん。
この壁が結構たかいんだよな。

これはUITableViewに値aaaaをセットする方法。
自分ように復習するためのメモも兼ねています。

ViewController

    //データのセット
    var cellItems = NSMutableArray()

    func MydataSet() -> NSArray{

        for var i = 0; i < 4; i++ {
            self.cellItems[i] = "aaaaa"
            println(i)
        }
        return cellItems

    }

ここでは、大元の「ViewController」の中に、cellItemsというマルチな配列をまず宣言しています。
そして、MydataSetというメソッドで、マルチな配列(cellItems)の中に、"aaaaa"という文字列を追加させます。
そしてMydataSet()という値を最終的にcellItemsとします。
(return cellItems がその部分)

ViewController

    //セクションを設定している
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        var cellItemsCount:Int = MydataSet().count

        return cellItemsCount
    }

    //cellを設定している
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
        var cellItemsContent = MydataSet()

        var cell = tableView.dequeueReusableCellWithIdentifier("titlecell") as UITableViewCell
        cell.textLabel?.text = cellItemsContent[indexPath.row] as? String
        return cell
    }

そして、セクション(テーブルの行)を設定しているパーツとその一行の中身を設定しているパーツでMydataSetを呼び出します。それぞれ、varで新しく値を作り、その中にメソッド自体を呼び出す感じ。
なんとなく、わかってきた気がする。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0