Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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 如何在UITextView中设置选择?_Ios_Uitableview_Uitextview - Fatal编程技术网

Ios 如何在UITextView中设置选择?

Ios 如何在UITextView中设置选择?,ios,uitableview,uitextview,Ios,Uitableview,Uitextview,我有一个UITextView,它位于UITableViewCell中。要选择UITextView中的内容,我将使用以下代码 [UITextView select:self]; [UITextView setSelectedRange:NSMakeRange(start,length)]; 加载UITableView后,将调用以下方法 numberofrowsinssection:(NSInteger)节 cellforrowatinedexpath:(nsindepath*)indepath

我有一个
UITextView
,它位于
UITableViewCell
中。要选择
UITextView
中的内容,我将使用以下代码

[UITextView select:self];
[UITextView setSelectedRange:NSMakeRange(start,length)];
加载
UITableView
后,将调用以下方法

  • numberofrowsinssection:(NSInteger)节
  • cellforrowatinedexpath:(nsindepath*)indepath
  • heightforrowatinexpath:(nsindepath*)indepath
  • 我的问题是,我应该将此代码放在哪里才能使
    UITextView
    获得焦点


    谢谢你的回答

    确保您已实施

    <UITextFieldDelegate>
    
    但是你必须把它设置好

    textFiled.delegate = self;
    

    如果我正确理解你的问题

    如果要在启动时关注textView,则需要将代码放在
    cellForRowAtIndexPath:(NSIndexPath*)indexPath
    中,因为您要将UITextView添加到UITableViewCell,而tableView单元格是在该数据源方法中创建/重用的

    如果你想让它专注于行的点击,那么利用

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
    

    希望这有帮助。

    您应该将代码放在
    viewdide
    方法中。首先,将目标单元格滚动到视图中,使其可见:

    scrollToRowAtIndexPath:atScrollPosition:animated:
    
    然后,获取要将输入导入的单元格:

    cellForRowAtIndexPath:
    

    现在将单元格强制转换为您类型的单元格,抓取它的
    UITextView
    ,进行选择,最后给它焦点。

    调用-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)通过传递indepath来完成indepath…然后用这个方法完成您的工作。谢谢您的信息。我的目标是在加载textview后对其进行聚焦。而且,当该行被点击时就不会了。然后您可以将它放在
    cellforrowatinexpath:
    delegate方法中
    cellForRowAtIndexPath: