Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在swift中将数组放入标签 @iAction func generateBtn(发送方:UIButton){ 设strt=UInt32(strtNum.text!) 让end=UInt32(endNum.text!) 让ttlNums=Int(amtNu_Ios_Swift_Labels_Arc4random - Fatal编程技术网

Ios 在swift中将数组放入标签 @iAction func generateBtn(发送方:UIButton){ 设strt=UInt32(strtNum.text!) 让end=UInt32(endNum.text!) 让ttlNums=Int(amtNu

Ios 在swift中将数组放入标签 @iAction func generateBtn(发送方:UIButton){ 设strt=UInt32(strtNum.text!) 让end=UInt32(endNum.text!) 让ttlNums=Int(amtNu,ios,swift,labels,arc4random,Ios,Swift,Labels,Arc4random,在swift中将数组放入标签 @iAction func generateBtn(发送方:UIButton){ 设strt=UInt32(strtNum.text!) 让end=UInt32(endNum.text!) 让ttlNums=Int(amtNums.text!) 设x=RandomNum() var z=0 而这里的主要问题是,数组在每次循环迭代中都是新创建的,并且在每次循环迭代中都会设置标签。这意味着数组将只包含在该迭代中生成的元素,之后会重置为新数组,并添加新元素。数组需要在开始

在swift中将数组放入标签
@iAction func generateBtn(发送方:UIButton){
设strt=UInt32(strtNum.text!)
让end=UInt32(endNum.text!)
让ttlNums=Int(amtNums.text!)
设x=RandomNum()
var z=0

而这里的主要问题是,数组在每次循环迭代中都是新创建的,并且在每次循环迭代中都会设置标签。这意味着数组将只包含在该迭代中生成的元素,之后会重置为新数组,并添加新元素。数组需要在开始时初始化一次t、 并在循环中重复向其添加元素,然后在最后放入标签一次

@IBAction func generateBtn(sender: UIButton) {
    let strt = UInt32(strtNum.text!)
    let end = UInt32(endNum.text!)
    let ttlNums = Int(amtNums.text!)

    let x = RandomNum()


    var z = 0

    while z<ttlNums{
        let y = x.rndNumGen(strt!, end: end!)
        z += 1
        var h = [String]()
        h.append(String(y))
        let display:String = h.joinWithSeparator(", ")

        winningNums.text = display
        print (display)

    }    
}
@iAction func generateBtn(发送方:UIButton){
保护让startText=strtNum.text,让start=UInt32(startText),
让endText=endNum.text,让end=UInt32(endText),
让ttlText=amtNums.text,让ttlNums=UInt32(ttlText)else{
//其中一个是零,在这里优雅地处理它
返回
}
设randomGenerator=RandomNum()
var h=[String]()
h、 储备容量(ttlNums)

对于0中的uu..在
主体中创建新的空变量
h
时,是否打算这样做?
@IBAction func generateBtn(sender: UIButton) {
    guard let startText = strtNum.text, let start = UInt32(startText),
          let endText = endNum.text, let end = UInt32(endText),
          let ttlText = amtNums.text, let ttlNums = UInt32(ttlText) else {
              //one of these is nil, handle it gracefully here
              return
          }

    let randomGenerator = RandomNum()

    var h = [String]()
    h.reserveCapacity(ttlNums)
    for _ in 0..<ttlNums {
        let randomNum = randomGenerator.rndNumGen(start, end: end)
        h.append(String(RandomNum))
    }

    let display = h.joinWithSeparator(", ")

    winningNums.text = display
    print(display)
}