【发布时间】:2016-01-03 23:23:38
【问题描述】:
我目前正在尝试创建一个类似于 Apple 提醒 的待办事项应用程序。现在,当我通过单击UIButton 添加新任务时,会创建一个包含UITextfield 的新单元格并将其分配为第一响应者。但是,当我这样做时,键盘按预期显示,但没有光标,也无法编辑。当我再次单击文本字段时,我可以按预期进行编辑。
任何帮助将不胜感激。
@IBAction func addTask(sender: UIBarButtonItem)
{
// Add a new task
let newIndexPath = NSIndexPath(forRow: tasks.count, inSection: 0)
let task = Task(name: "")!
tasks.append(task)
tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Bottom)
let cellIdentifier = "TaskTableViewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: newIndexPath) as! TaskTableViewCell
let db_Task = PFObject(className: "Task")
db_Task["TaskName"] = ""
db_Task["Completed"] = false
db_Task["group"] = getGroupId()
db_Task.saveInBackgroundWithBlock
{(success: Bool, error: NSError?) -> Void in
print("Object has been saved.")
}
cell.nameLabel.becomeFirstResponder()
}
【问题讨论】:
-
nameLabel 是您的文本字段吗?刚想到名字……
标签: ios swift uitableview uitextfield