UITextView在UITableViewCell中,自动更正无法解除

时间:2012-01-24 15:56:25

标签: ios objective-c cocoa-touch uitableview uitextview

UITextView内有UITableViewCell。它按预期工作,除了我不能忽略弹出的自动更正建议。这就是我的-tableView:cellForRowAtIndexPath:方法:

- (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 个答案:

答案 0 :(得分:1)

@Peter Warbo:我怀疑有以下情况:

  • 默认情况下,UIImageView的userInteraction属性设置为NO。在气球图像视图对象上将其设置为YES。 balloon.userInteractionEnabled = YES;

HTH