【发布时间】:2015-12-08 07:01:18
【问题描述】:
据我了解,我无法使用插座连接将单元格中的按钮连接到 TableViewController。 我可以使用操作连接将单元格中的按钮连接到我的 TableView。这是我的大问题的根源。
在我的单元格中,我有一个 textview、一个带有重叠按钮的 imageView 和一个发送按钮。 这就是细胞
我使用 imagePicker 将图像分配给 imageView。 imagePicker 必须从 tableViewController 打开(不能在单元格中打开)。
var MyImage = UIImage?()
var MyName = String()
var MyStatus = String()
// This is ImgButton that overlays the imageView
@IBAction func MyImageButtonAction(sender: AnyObject) {
// Select Image
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
// The image chosen by the user is now called MyImage
MyImage = image
self.dismissViewControllerAnimated(true, completion: nil)
}
现在,当点击发送按钮时,我将 MyImage 设为 Parse.com 的 PFFile 并将其发送到数据库。我不需要在这里提供完整的细节。这部分工作正常。
问题是我不知道如何正确地将单元格连接到 tableViewController,以便将值从一个传输到另一个。我想从单元格中获取 textView.text 到 tableViewController 以便从那里我可以将它与图像一起发送到数据库。另一个问题是,尽管用户可以选择图像并将其发送到数据库,他们无法将所选图像放入他们的 imageView。
这是我尝试将单元格连接到 tableViewController:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MyStatusTableViewCell", forIndexPath: indexPath) as! MyStatusTableViewCell
cell.MyName.text = MyName
return cell
}
我希望他的代码意味着 MyName 现在是包含用户在单元格中的 textView.text 中输入的 .text 的变量。我尝试将 MyName 发送到数据库,但它是空的。
如何将 tableViewCell 中的 textView.text 获取到我的数据库中?
【问题讨论】:
-
我也尝试过使用一个发送按钮来执行两个功能:将图像从 ViewController 发送到数据库并将 .text 从单元格发送到数据库,但它不会让我这样做
标签: ios swift uitableview cell viewcontroller