在标签上放置标准字符串

时间:2016-01-08 09:41:55

标签: ios swift swift2 xcode7

我正在尝试为每个用户创建一个显示不同文本的标签,在此标签之前有一个标准文本,但不在.xib文件的单元格内。

在知道这件事之前我做了什么

import UIKit

class profileViewController: UIViewController {


@IBOutlet var lblUsersname: UILabel!
@IBOutlet var lblUserspoints: UILabel!
@IBOutlet var imgViewUserAvatar: UIImageView!

var profileJson : [String:AnyObject] = [ : ]
var userid = ""
var usersname = ""
var userspoints = ""
var usersavatar = ""
var pointtxt = "Points: "

override func viewDidLoad() {
    super.viewDidLoad()

    let defaults = NSUserDefaults.standardUserDefaults()
    if let usersid = defaults.stringForKey("usersId") {
        userid = usersid
        fetchDatas()
        lblUsersname.text = usersname
        lblUserspoints.text = userspoints
    }else{
        print("Error")
    }

    if let checkedUrl = NSURL(string: usersavatar) {
        downloadImage(checkedUrl)
    }

}

func fetchDatas(){

    let urlara = NSLocalizedString("profileRequest", comment: "")
    let loginRequest = receiveData(data1: "id=\(userid)", url1: NSURL(string: urlara)!)
    profileJson = loginRequest.fetchData()

    if let locationsArray = profileJson["profile"] as? [[String:AnyObject]] {
        for locationDictionary in locationsArray {
            if let name = locationDictionary["name"] as? String {
                usersname = name
            }
            if let points = locationDictionary["points"] as? String {
                userspoints = points
            }
            if let avatar = locationDictionary["avatar"] as? String {
                usersavatar = avatar
            }

        }
    }

}

所以现在只显示点数 而我正试图让它显示

Points: lblUserpoints

任何人都有任何想法?

1 个答案:

答案 0 :(得分:0)

经过一些尝试,我发现了它。改变了行

lblUserspoints.text = userspoints

到这个

lblUserpoints.text = String(pointtxt) + userpoints

我有所需的输出

Points: 2910