0
UITableViewCell
の中にUITextView
があります。それは私がポップアップするautocorrectionの提案を却下することができないことを除いて、期待どおりに働いています。UITableViewCellのUITextViewは、自動訂正を終了できません。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *messageCellIdentifier = @"MessageCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:messageCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:messageCellIdentifier];
}
// Set the background view of the cell to be transparent
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIImage *ballonImage = [[UIImage imageNamed:@"ChatBubbleGray.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
NSString *text = @"Touch To Type";
// This imageView will be the background of the UITextView
UIImageView *balloon = [[UIImageView alloc] initWithImage:ballonImage];
balloon.frame = CGRectMake(0.0, 0.0, 300, 140);
CGRect textViewFrame;
textViewFrame.origin.x = balloon.frame.origin.x + 10;
textViewFrame.origin.y = balloon.frame.origin.y + 5;
textViewFrame.size.width = balloon.frame.size.width - 12;
textViewFrame.size.height = balloon.frame.size.height - 15;
self.messageTextView = [[UITextView alloc] initWithFrame:textViewFrame];
self.messageTextView.backgroundColor = [UIColor clearColor];
self.messageTextView.returnKeyType = UIReturnKeyDefault;
self.messageTextView.editable = YES;
self.messageTextView.scrollEnabled = YES;
self.messageTextView.autocorrectionType = UITextAutocorrectionTypeYes;
self.messageTextView.autocapitalizationType = UITextAutocapitalizationTypeSentences;
self.messageTextView.delegate = self;
self.messageTextView.text = text;
self.messageTextView.font = [UIFont systemFontOfSize:14.0];
[balloon addSubview:self.messageTextView];
[cell.contentView addSubview:balloon];
return cell;
}
うわあ、それは簡単でした。本当にありがとう! –
BTW、userInteractionEnabledをUIImageViewに設定します。私のUITableViewDelegateメソッド '-tableView:didSelectRowAtIndexPath:'はトリガされません。どうすればこれを克服できますか? –
UITextViewオブジェクトの背景イメージとしてballonビューを設定しようとしている場合は、次のようにしてください: UITextView * textView = [[UITextView alloc] initWithFrame:CGRectMake(0、0、300、140)]; [textView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@ "balloon.png"]]]; textView.contentInset = UIEdgeInsetsMake(10,10,0,0); [cell.contentView addSubView:textView]; – Jimit