【发布时间】:2015-09-11 22:23:17
【问题描述】:
当按下“保存”按钮时,我正在尝试访问嵌套在 UITableView 中的 UITextFields 的内容。
但是,调试(如下所示)表明 我可以访问除文本之外的 texfield 的任何内容...
在按下按钮之前我在里面输入的任何内容都没有影响......
我觉得我应该使用 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)")
}
}
控制台打印以下内容,这证明问题不在我的表格视图中,我的“for”循环访问它也不在文本字段本身(或者它是“outlet”):
indexPath : {length = 2, path = 0 - 0},记录: 和TextField:+ >。 测试: [NSParagraphStyle:对齐 0,LineSpacing 0,ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 4, 制表符 ( 28升, 56升, 84升, 112升, 140L, 168升, 196升, 224升, 252升, 280L, 308升, 336L ), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0, NSShadow: NSShadow {0, -1} color = {(null)}, NSFont: 字体系列: ".HelveticaNeueInterface-Regular";字体粗细:正常;字体样式: 普通的;字体大小:14.00pt,NSColor:UIDeviceRGBColorSpace 0 0 0 1] 和 Optional() 和 Optional("First Name") 和 0 indexPath : {长度 = 2, 路径 = 0 - 1}, 记录最后:,记录第一个:和文本字段:indexPath : {长度 = 2, 路径 = 0 - 2}, 录制的图像:可选(NSMutableData)和 UIImageView 的图像: 可选(尺寸 {1500, 1001} 方向 0 规模 1.000000)
【问题讨论】:
标签: ios swift uitableview cocoa-touch uitextfield