Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在swift的自定义单元格中获取UITextView数据_Ios_Swift_Uitableview - Fatal编程技术网

Ios 在swift的自定义单元格中获取UITextView数据

Ios 在swift的自定义单元格中获取UITextView数据,ios,swift,uitableview,Ios,Swift,Uitableview,我有一个自定义单元格,其中有一个UITextView,并且outlet的UITextView位于自定义单元格文件中 现在在我的视图控制器中我有了表格视图,我创建了自定义单元格并将其添加到我的表格中。 在此之后,我无法访问UITextView并在customCell文件中获取其数据作为其outlet。我无法将插座移动到我的viewController,因为我需要它。 如何执行此操作(在我的viewController中访问UITextView)?您需要在viewController中声明一个局部变

我有一个自定义单元格,其中有一个
UITextView
,并且
outlet
UITextView
位于自定义单元格文件中

现在在我的
视图控制器中
我有了
表格视图
,我创建了自定义单元格并将其添加到我的表格中。 在此之后,我无法访问
UITextView
并在customCell文件中获取其数据作为其
outlet
。我无法将插座移动到我的
viewController
,因为我需要它。
如何执行此操作(在我的
viewController
中访问
UITextView

您需要在
viewController
中声明一个局部变量以获取
UITextView
的数据。然后执行
tableView
s
delegate
方法

 //this is your local variable declared in viewCOntroller
 var myTextViewText: String?

//And this is your delegate method
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableView.cellForRowAtIndexPath(indexPath) as! YourCell
    myTextViewText = cell.textView.text //here you will get the text of your cell's textView
}

您需要在
viewController
中声明一个局部变量,以获取
UITextView
的数据。然后执行
tableView
s
delegate
方法

 //this is your local variable declared in viewCOntroller
 var myTextViewText: String?

//And this is your delegate method
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableView.cellForRowAtIndexPath(indexPath) as! YourCell
    myTextViewText = cell.textView.text //here you will get the text of your cell's textView
}

您可以使用
viewController
设置单元格的
textView
的代理,首先在
cellForRowAtIndexPath

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!  {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomTableCell 
    cell.textView.delegate = self
    cell.textView.tag = indexPath.row //In case you have multiple textView
    return cell
}
现在,您可以在其
UITextViewDelegate
方法中获得此文本视图

func textViewDidBeginEditing(textView: UITextView) {
    print(textView.text)
} 

您可以使用
viewController
设置单元格的
textView
的代理,首先在
cellForRowAtIndexPath

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!  {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomTableCell 
    cell.textView.delegate = self
    cell.textView.tag = indexPath.row //In case you have multiple textView
    return cell
}
现在,您可以在其
UITextViewDelegate
方法中获得此文本视图

func textViewDidBeginEditing(textView: UITextView) {
    print(textView.text)
} 

谢谢,但我正在尝试在点击按钮时获取用户输入。这里不会这样做,因为用户在更改输入后可能不会选择行。谢谢,但我正在尝试在点击按钮时获取用户输入。这里不会这样做,因为用户在更改输入后可能不会选择行。