gpt4 book ai didi

ios - 访问 UITableView 中嵌套的 UITextField 文本内容

转载 作者:行者123 更新时间:2023-11-30 14:16:51 25 4
gpt4 key购买 nike

当按下“保存”按钮时,我试图访问嵌套在 UITableView 中的 UITextFields 的内容

但是,调试(如下所示)表明我可以访问除文本之外的有关文本字段的任何内容...

无论我在按下按钮之前在其中输入什么内容都不会产生任何影响...

我觉得我应该使用 UITextField Delegate,但既不明白为什么也不明白如何...

这是我正在使用的代码:

@IBAction func saveNewGuestButton(sender: UIBarButtonItem) {
let entity : NSEntityDescription = NSEntityDescription.entityForName("Guest", inManagedObjectContext: self.managedObjectContext)!
// Initialize Record
let record : Guest = Guest(entity:entity, insertIntoManagedObjectContext:managedObjectContext)
// Populate Record
for i in 0..<3
{
let indexPath : NSIndexPath = NSIndexPath(forRow: i, inSection: 0)
let cell = tableView(self.tableView, cellForRowAtIndexPath: indexPath) as! newGuestProtoCell
if i==0
{
record.guestFirst = cell.newGuestFirstNameTextField.text
println("indexPath :\(indexPath), recorded : \(record.guestFirst) and TextField : \(cell.newGuestFirstNameTextField.text) + \(cell.newGuestFirstNameTextField). test : \(cell.newGuestFirstNameTextField.defaultTextAttributes) and \(cell.newGuestFirstNameTextField.attributedText) and \(cell.newGuestFirstNameTextField.placeholder) and \(cell.newGuestFirstNameTextField.tag)")
}
if i==1
{
record.guestLast = cell.newGuestLastNameTextField.text

println("indexPath :\(indexPath), recorded Last : \(record.guestLast), recorded first : \(record.guestFirst) and textfield : \(cell.newGuestLastNameTextField.text)")
//newGuest["lastName"] = cell.newGuestLastNameTextField.text
}
if i==2 && guestImage != nil
{

record.guestImage = UIImagePNGRepresentation(guestImage) as NSData
println("indexPath :\(indexPath), recorded image: \(record.guestImage.superclass) and UIImageView's image : \(cell.guestImageIV.image)")
}
}

控制台打印以下内容,这证明问题不在于我的表格 View 、访问它的“for”循环,也不在于文本字段本身(或者它是“导出”):

indexPath : {length = 2, path = 0 - 0}, recorded : and TextField : + >. test : [NSParagraphStyle: Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 4, Tabs ( 28L, 56L, 84L, 112L, 140L, 168L, 196L, 224L, 252L, 280L, 308L, 336L ), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0, NSShadow: NSShadow {0, -1} color = {(null)}, NSFont: font-family: ".HelveticaNeueInterface-Regular"; font-weight: normal; font-style: normal; font-size: 14.00pt, NSColor: UIDeviceRGBColorSpace 0 0 0 1] and Optional() and Optional("First Name") and 0 indexPath : {length = 2, path = 0 - 1}, recorded Last : , recorded first : and textfield : indexPath : {length = 2, path = 0 - 2}, recorded image: Optional(NSMutableData) and UIImageView's image : Optional( size {1500, 1001} orientation 0 scale 1.000000)

最佳答案

通过阅读你的代码,你做错了事情:

let cell = tableView(self.tableView, cellForRowAtIndexPath: indexPath) as! newGuestProtoCell

cellForRowAtIndexPath 用于准备 View 以显示它。所以它应该清楚你输入的内容,并填写正确的记录内容。 (indexpath 处的记录)。然后你应该得到一个 textview 的文本为 null 的 View 。

关于如何取出值,可以在具体的方法中设置委托(delegate)UITextFieldDelegate。 tableView(self.tableView,cellForRowAtIndexPath:indexPath)。

关于ios - 访问 UITableView 中嵌套的 UITextField 文本内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31048194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com