Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.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
Iphone 如果单元中有UITextView,则无法选择UITable单元_Iphone_Objective C_Ios - Fatal编程技术网

Iphone 如果单元中有UITextView,则无法选择UITable单元

Iphone 如果单元中有UITextView,则无法选择UITable单元,iphone,objective-c,ios,Iphone,Objective C,Ios,我已经在我的手机中添加了一个UITextView。如果用户单击了UITextView所在的单元格,则不会调用didSelectRowAtIndexPath:,除非用户单击了UITextView未覆盖的区域。是否有工作需要解决,或者我做错了什么 UITextView *txtview = [[UITextView alloc] initWithFrame:CGRectMake(75, 1, 250, 34)];//init and create the UIWebView txtview.auto

我已经在我的手机中添加了一个
UITextView
。如果用户单击了
UITextView
所在的单元格,则不会调用
didSelectRowAtIndexPath:
,除非用户单击了
UITextView
未覆盖的区域。是否有工作需要解决,或者我做错了什么

UITextView *txtview = [[UITextView alloc] initWithFrame:CGRectMake(75, 1, 250, 34)];//init and create the UIWebView
txtview.autoresizesSubviews = NO;
//txtview.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
[txtview setBackgroundColor:[UIColor grayColor]];
[txtview setFont:[UIFont fontWithName:@"Helvetica" size:15]];
txtview.textColor = [UIColor blackColor];
txtview.scrollEnabled = NO;

[txtview setOpaque:NO];
//[txtview setDelegate:self];
txtview.editable = NO;
txtview.text = aBlogRss.title;
[txtview setContentInset:UIEdgeInsetsMake(-11,-8,0,0)];
//[txtview loadHTMLString:htmlString baseURL:nil];
[cell addSubview:txtview];
[txtview release]; 
非常感谢,,
-Code

您应该在viewDidLoad:中创建UITextView,并且只保留[cell addSubview:txtview]单元格中的code>行索引路径:

或者,您可以使用:
[cell setAccessoryView:txtView]

还有一件事,你是如何创建你的手机的?

试试看

txtView.userInteractionEnabled = YES;

应该这样做。

该单元格使用一次还是可能无限次?如果是一次,那么你可以使用

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
并手动插入indexPath,因为您知道它位于何处


如果要重复使用单元格,请尝试将textfield的“tag”属性与行一起设置,然后当UITextView检测到触摸时,使用其委托方法之一调用上面的UITableView方法,提供从UITextView的标记派生的NSIndexPath。

我认为解决方案实际上是

txtView.userInteractionEnabled = NO;
这将向父视图传递接触。。或者在本例中为
UITableViewCell
。如果要在多个位置执行此操作,最好将
UITAbleViewCell
子类化

或者,您可以将类设置为UITextViewDelegate,将txtView.delegate设置为self,并实现

-(BOOL)文本视图应开始编辑:(UITextView*)文本视图


然后通过
self.tableview
选择合适的
UITableViewCell
。。但那简直就是一次黑客攻击

是的,行没有被选中是有意义的,因为它上面有一个
textView
。这里有一些方法可以解决这个问题

  • 您可以设置
    文本视图
    框架,以便为选择行提供空间

  • 您可以将每个textView(每行)设置为属性,并找出选择了哪个
    textView
    。基于此,您可以调用
    textViewDidBeginEditing
    方法并以编程方式使该行可选

    [self.tableView selectRowAtIndexPath:indexPath animated:YES  scrollPosition:UITableViewScrollPositionNone];
    
    参考资料:


  • 注意:您必须将每个
    textView
    逻辑链接到它对应的
    cellIndexPath

  • 向单元格中添加UITapgestureRecognitor

  • 编写一个手势处理代码,如下所示

    - (IBAction)handleTap:(UITapGestureRecognizer *)sender
    {
        [self.tableView selectRowAtIndexPath:
         [self.tableView indexPathForCell:(UITableViewCell *)sender.view]
                                    animated:NO
                              scrollPosition:UITableViewScrollPositionNone];
    }
    
  • 连接它们

  • 您将获得可选的UITextView和可选的UITextViewCell