あなたはタップイベントを処理するためにしました。.. .numberOfTapsRequired = 1
または
これを行うには、UITableViewCellに1つ埋め込む必要があります。しかし、カスタムセルを作成する必要はありません。ここであなたがやりたいだろうかの基本的な考え方は次のとおりです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UITextView *comment = [[UITextView alloc] initWithFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, tableView.rowHeight)];
comment.editable = NO;
comment.delegate = self;
[cell.contentView addSubview:comment];
[comment release];
}
return cell;
}
あなたは、もちろん、あなたがセルに付属している標準44ptの高さをしたくない場合は、あなたのrowHeightのを設定する必要があります。実際のセルが必要な場合は、独自のロジックを追加して、必要なセルだけをtextViewにする必要がありますが、これが基本的な考え方です。残りの部分はあなたのフィッティングに合わせてカスタマイズすることができます。これが役に立ちますようにお願いします。
EDIT:テキストビューをバイパスして自分のセルに移動するには、これについて2通りの方法があります。
1)あなたは、カスタムのTextViewクラスを作成し、スーパーにメッセージを送信するためにtouchesBeganを上書きすることができます
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
}
これはあなたのtableViewされるであろう、そのスーパーにタッチイベントを送信します。カスタムUITableViewCellを作成したくないと考えると、おそらくカスタムtextViewクラスを作成したくないと思います。これは私をオプション2に導く。
2)textViewを作成するときは、comment.editable = NO;を削除します。編集可能な状態に保つ必要がありますが、デリゲートメソッドでそれを修正します。あなたのコードで
、あなたはTextViewのデリゲートメソッドを挿入したいと思うでしょうし、我々はそこからすべての私たちの仕事をやる:
EDIT:のUITableViewController
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
// this method is called every time you touch in the textView, provided it's editable;
NSIndexPath *indexPath = [self.tableView indexPathForCell:textView.superview.superview];
// i know that looks a bit obscure, but calling superview the first time finds the contentView of your cell;
// calling it the second time returns the cell it's held in, which we can retrieve an index path from;
// this is the edited part;
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
// this programmatically selects the cell you've called behind the textView;
[self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
// this selects the cell under the textView;
return NO; // specifies you don't want to edit the textView;
}
た場合に使用するには、このコードを変更しますそれはあなたが望むものではありません、私に知らせてください、そして、私たちはあなたをソートします。
長押しジェスチャ認識機能を使用できないのはなぜですか? – user3182143
は、助けを目的としたコードを表示します – user3182143
@ user3182143多くのコーディングはありません。 UITextViewはstoryBoardで作成されます。 cellForRowAtIndexPathでは、attributedText.addAttribute(NSLinkAttributeName、value:linkAddress、range:linkWordRange)を使用していくつかのリンクを追加します。そして、attributedTextをtextViewに割り当ててください。タップするだけで簡単にリンクを開くことができます。 –