简体   繁体   中英

How to create name for the textField dynamically [SWIFT]?

How to create name for the textField dynamically for next parsing value, which will be the name of the textField? It will looks like UID_score . UID - this is user id, which is fetching from CoreData.

I'm not absolutely sure about what you want to achieve, but one way to generate a number of TextFields that match with the number of user Ids could be as follows. You can also set tag of the TextField to keep track of each user.

let userIds = [5, 8, 9, 10, 12]
let textFields = (0 ..< userIds.count).map { _ in UITextField() }
for i in 0..<userIds.count {
    textFields[i].frame = CGRect(x: 10 * i, y: 10, width: 30, height: 30)
    textFields[i].tag = userIds[i]
    view.addSubview(textFields[i])
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM