2010-11-07 7 views
0

J'ai un UITableViewCell qui a un UITextView intégré. L'objectif est de créer une cellule qui se développe automatiquement lors de l'édition. Le problème en ce moment est que lorsque UITableViewController envoie setEditing: YES, UITextView défile et découpe une partie du texte en haut.UITextView setEditing: YES fait-il défiler le contrôle du TextView?

Je suis sûr qu'il ya une meilleure façon de le faire, mais je ne sais pas comment ...

#import "PLTextViewCell.h" 

@implementation PLTextViewCell 

@synthesize delegate=_delegate; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { 
     _textView = [[UITextView alloc] initWithFrame:CGRectMake(90, 0, 200, 80)]; 
     [_textView setEditable:NO]; 
     [_textView setFont:[UIFont systemFontOfSize:15.0]]; 
     [_textView setDelegate:self]; 
     [_textView setScrollEnabled:NO]; 
     [[self contentView] addSubview:_textView]; 
    } 
    return self; 
} 

- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    [super setEditing:editing animated:animated]; 
    [_textView setEditable:editing]; 
    [_textView scrollRangeToVisible:NSMakeRange(0, 1)]; 
    [self textViewDidChange:_textView]; 
} 

- (void)dealloc { 
    [_textView dealloc]; 
    [super dealloc]; 
} 

- (void)setTextValue:(NSString *)value { 
    [_textView setText:value]; 
    [self textViewDidChange:_textView]; 
} 

- (NSString *)textValue { 
    return [_textView text]; 
} 

- (CGFloat)cellHeight { 
    CGSize mySize = [_textView contentSize]; 
    NSLog(@"cell height: %f", mySize.height); 
    return mySize.height; 
} 

#pragma mark - 
#pragma mark Text view delegate 

- (void)textViewDidChange:(UITextView *)textView { 
    CGSize mySize = [_textView contentSize]; 
    if (mySize.height > self.bounds.size.height) { 
     [textView scrollRectToVisible:CGRectMake(0,textView.contentSize.height-1,1,1) animated:NO]; 
     if ([self delegate] != nil) { 
      [[self delegate] tableViewCellDidChangeHeight:self]; 
     } 
     [textView setFrame:CGRectMake(90, 0, mySize.width, mySize.height)]; 
     [self setNeedsLayout]; 
    } 
} 

@end 

Puis la vue Table met en oeuvre une méthode de délégation:

- (void)tableViewCellDidChangeHeight:(PLTextViewCell *)cell { 
    [self.tableView beginUpdates]; 
    [self.tableView endUpdates]; 
} 

Des idées? Est-ce que je fais tout faux?

Répondre

0

Il s'avère que c'était le UIEdgeInset combiné avec mon textview n'étant pas assez grand. Mon erreur!

Questions connexes