2012-01-24 7 views
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; 
} 

答えて

1

@Peter Warbo:デフォルトUIImageViewのuserInteractionプロパティがNOに設定されていることで

  • :私は次のよう疑ってるこれは、私の-tableView:cellForRowAtIndexPath:方法は次のようになります。 ballonイメージビューオブジェクトでYESに設定します。 balloon.userInteractionEnabled = YES;

HTH

+0

うわあ、それは簡単でした。本当にありがとう! –

+0

BTW、userInteractionEnabledをUIImageViewに設定します。私のUITableViewDelegateメソッド '-tableView:didSelectRowAtIndexPath:'はトリガされません。どうすればこれを克服できますか? –

+0

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

関連する問題