Mus*_*afa 5 iphone uitableview uitextview ios
我有我的问题UITableViewCellselection.I正在使用 UITableViewCell一个UITextView子视图.在UITextView启用用户交互的情况下,该对象不可编辑,不可滚动.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@"DemoCell" owner:self options:nil]objectAtIndex:0];
cell. accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
if([distanceArray count]){
UILabel *label1=(UILabel*)[cell viewWithTag:1];
label1.text=[locationNameArray objectAtIndex:[indexPath section]];
label1.textColor=[UIColor blueColor];
UILabel *label2=(UILabel*)[cell viewWithTag:2];
[label2 setText:[distanceArray objectAtIndex:[indexPath section]]];
UITextView *tview=(UITextView*)[cell viewWithTag:3];
[tview setText:[discriptionArray objectAtIndex:[indexPath section]]];
return cell;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailedLocationVIew *dView=[[DetailedLocationVIew alloc]initWithNibName:@"DetailedLocationVIew" bundle:nil];
[self.navigationController pushViewController:dView animated:YES];
[dView release];
}
Run Code Online (Sandbox Code Playgroud)
如果我选择了单元格UITextView,代表didSelectRowIndexPath不会调用.除了UITextView 对象和选择工作正常吗?为什么选择不能在UITextView上工作?
Sur*_*rma 13
使用tview.userInteractionEnabled=NO;它将解决您的问题.
如果这不能解决您的问题,那么试试这个
for(UIView * cellSubviews in cell.subviews)
{
cellSubviews.userInteractionEnabled = NO;
}
Run Code Online (Sandbox Code Playgroud)
它循环遍历单元格内的所有子视图并将userInteractionEnabled属性设置为NO.
这些建议在iOS 6中对我不起作用.以下是有效的.
在你的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
添加这个:
cell.textView.dataDetectorTypes = UIDataDetectorTypeAll;
cell.textView.editable = NO;
cell.textView.userInteractionEnabled = YES;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(forwardToDidSelect:)];
cell.tag = indexPath.row;
[cell.textView addGestureRecognizer: tap];
Run Code Online (Sandbox Code Playgroud)
随着:
- (void) forwardToDidSelect: (UITapGestureRecognizer *) tap
{
[self tableView: self.tableView didSelectRowAtIndexPath: [NSIndexPath indexPathForRow: tap.view.tag inSection: kTextViewCellSection]];
}
Run Code Online (Sandbox Code Playgroud)
设置editable = NO后,似乎有必要设置userInteractionEnabled = YES.在XIB中设置这些似乎不起作用.
| 归档时间: |
|
| 查看次数: |
7749 次 |
| 最近记录: |