(swift2)变量在if语句中没有变化

问题描述 投票:-1回答:1

我面临的问题是我无法更新变量lin。我尝试了多个时间f :)。要获得代码中的relevode快速第二行是标识变量的位置,然后如果你滚动到代码的底部,这是变量假设要更改但不是

let menable = UITabletgView()
let arfSorces:[String] = ["C"]




public func runMenu(){
    if let window = UIApplication.sharedApplication().keyWindow{

        dimming.frame = window.frame
        dimming.backgroundColor = UIColor(white: 0.9, alpha: 0.5087)

        dimming.addGestureRecognizer(UITapGestureRecognizer(target: self, action: Selector("eefefef")))

        let height: CGFloat = 100000
        let y = window.frame.height - height + height
        menuTable.frame = CGRect(x: 10, y: window.frame.height, width: window.frame.height, height: height)

        window.addSubview(dimming)
        window.addSubview(mee)

       eView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("c", forIndexPath: indexPath)as UITableViewCell
    e.textLabel?.text = ars[indexPath.item]
    return e
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 50000
}

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

    func RunLink(){
        if let v = c{
          98bdfe8daf6543d92"
swift swift2
1个回答
1
投票

在if语句中,您声明了一个全新的变量link1,它只存在于if语句中。更改

if arrayOfSorces[indexPath.item] == arrayOfSorces[0]{
    var link1 = "https://newsapi.org/v2/everything?sources=bbc-news&apiKey=a9ea5ee627044bd98bdfe8daf6543d92"
    RunLink()
}

if arrayOfSorces[indexPath.item] == arrayOfSorces[0]{
   link1 = "https://newsapi.org/v2/everything?sources=bbc-news&apiKey=a9ea5ee627044bd98bdfe8daf6543d92"
    RunLink()
}

(摆脱var。这会创建一个新变量,而不是更改现有变量中的值。)

© www.soinside.com 2019 - 2024. All rights reserved.