2012-01-24 73 views
0

我在UITableViewCell內有UITextView。它的工作方式和預期的一樣,只是我不能排除彈出的自動糾錯建議。這就是我的-tableView:cellForRowAtIndexPath:方法是這樣的:UITextView在UITableViewCell中,自動更正不能被駁回

- (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的用戶交互屬性設置爲NO。在您的氣球圖像視圖對象上將其設置爲YES。 balloon.userInteractionEnabled = YES;

HTH

+0

天吶,這是那麼簡單。謝謝一堆! –

+0

順便說一下,通過將userInteractionEnabled設置爲UIImageView。我的UITableViewDelegate方法'-tableView:didSelectRowAtIndexPath:'沒有被觸發。我該如何克服這一點? –

+0

如果您試圖將氣球視圖設置爲UITextView對象的背景圖像,那麼我會推薦以下內容: 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

相關問題