单击位于tableviewcell顶部的textview时无法导航

时间:2014-06-17 09:44:43

标签: ios7 textview tableviewcell

我有一个tableviewcell,我在其中显示RSS提要的标题,日期和网站名称。在这下面,我有一个文本字段,我正在显示一个简短的描述。我希望用户能够点击tableviewcell的任何部分来导航到新屏幕。目前,只有当我点击具有标题,日期和网站的单元格部分时,我才能这样做,但是在具有描述的文本视图的部分上却没有。我可以实现这样的事吗?如果是这样,我该怎么做?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NewsCell *cell = (NewsCell*)[tableView dequeueReusableCellWithIdentifier:@"NewsViewCell" forIndexPath:indexPath];

cell.titleLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"title"];

NSString *site = [[feeds objectAtIndex:indexPath.row] objectForKey:@"link"];

if ([site rangeOfString:@"dailymail"].location != NSNotFound) {
    site = @"Daily Mail";
}

else if (![site rangeOfString:@"theguardian"].location != NSNotFound){
    site = @"The Guardian";
}
else if (![site rangeOfString:@"football.co.uk"].location != NSNotFound) {
    site = @"Football UK";
}
else if (![site rangeOfString:@"football365"].location != NSNotFound) {
    site = @"Football 365";
}

cell.siteLabel.text = site;

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat: @"dd-MM-yyyy HH:mm:ss"];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSString *dateString = [dateFormat stringFromDate:[[feeds objectAtIndex:indexPath.row] objectForKey:@"pubDate"]];

cell.pubDateLabel.text = dateString;

NSString *newsDescription = [[feeds objectAtIndex:indexPath.row] objectForKey:@"description"];

CGRect textRect = [newsDescription boundingRectWithSize:CGSizeMake(310,NSUIntegerMax) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:12]} context:nil];

CGSize stringSize = textRect.size;

textV=[[UITextView alloc] initWithFrame:CGRectMake(5, 50, 310, stringSize.height+25)];

for(UIView *subview in cell.contentView.subviews)
{
    if([subview isKindOfClass: [UITextView class]])
    {
        [subview removeFromSuperview];
    }
}

if ([newsDescription isEqualToString:@""])
{
    newsDescription = @"Preview not available";

    textV.font = [UIFont italicSystemFontOfSize:12.0];

    textV.textColor = [UIColor grayColor];
}
else
{
    textV.font = [UIFont systemFontOfSize:12.0];

    textV.textColor = [UIColor blackColor];
}

textV.text = newsDescription;

textV.textAlignment = NSTextAlignmentLeft;


textV.editable = NO;

[cell.contentView addSubview:textV];


return cell;
}

1 个答案:

答案 0 :(得分:0)

通过查看下面的帖子,我想通了。只需将textView userInteractionEnabled设置为NO。

How to pass touch from a UITextView to a UITableViewCell