2016-07-14 4 views
-2

This are my codes, looking for a possible solution to the errorエラー - スウィフト

// 
// ViewController.swift 
// Login 
// 
// Created by MAC on 14/07/2016. 
// Copyright 2016 VerseCom. All rights reserved. 
// 

import UIKit 

class ViewController: UIViewController { 

    @IBOutlet weak var scrollview: UIScrollView! 

    let WIDTH : CGFloat = 320 
    let HIEGHT : CGFloat = 568 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     var i in 1..4 { 
      let img = UIImage(named: "/(i)") 
      let imgview = UIImageView(image: img) 
      self.scrollview.addSubview(imgview) 

     } 

     } 
    } 
+0

こんにちは@Odusina Timilehinは、StackOverflowのを歓迎して、ここにStackOverflowに質問をする方法にするためのガイドです:http://stackoverflow.com/help/how-to-ask – mgyky

+0

内のコードを試してみてください@Odusina Timilehinの下の私の答え – mgyky

+0

あなたが私の答えを見つけたら、この方法でそれを受け入れてください:http://meta.stackexchange.com/a/5235。 – mgyky

答えて

0

私はあなたのためのインループで数回をループにしたいと思いますが、あなたは、あなたのコード内でこのようにそれを使用します。

ここ
var i in 1...4 { 
... 
} 

がどのようですあなたがそれを使用する必要があります。

あなたがのためにインループな番号の範囲としてシーケンスを、反復処理するために使用し、文字列の配列内の項目、または文字。

この例では、5回表の最初のいくつかのエントリを出力します。

for index in 1...5 { 
    print("\(index) times 5 is \(index * 5)") 
} 

// 1 times 5 is 5 
// 2 times 5 is 10 
// 3 times 5 is 15 
// 4 times 5 is 20 
// 5 times 5 is 25 

別の例:

let base = 3 
let power = 10 
var answer = 1 
for _ in 1...power { 
    answer *= base 
} 
print("\(base) to the power of \(power) is \(answer)") 
// Prints "3 to the power of 10 is 59049" 

別:

let names = ["Anna", "Alex", "Brian", "Jack"] 
for name in names { 
    print("Hello, \(name)!") 
} 
// Hello, Anna! 
// Hello, Alex! 
// Hello, Brian! 
// Hello, Jack! 

と別:

let numberOfLegs = ["spider": 8, "ant": 6, "cat": 4] 
for (animalName, legCount) in numberOfLegs { 
    print("\(animalName)s have \(legCount) legs") 
} 
// ants have 6 legs 
// cats have 4 legs 
// spiders have 8 legs 

From Apple documentation

+0

は エラーが離れ –

+0

あなたの歓迎を行ってきましたありがとうございました、このような私の答えを受け入れてください。 – mgyky

関連する問題