开发者

iPhone - heightForRowAtIndexPath scroll problem when setting a TextView text

开发者 https://www.devze.com 2023-02-10 00:08 出处:网络
I have a problem with a tableview and a custom cell. I have the following code : - (void)viewDidLoad { [super viewDidLoad];

I have a problem with a tableview and a custom cell.

I have the following code :

- (void)viewDidLoad {
    [super viewDidLoad];
}

// =================================================================================================
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

// =================================================================================================
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 1;
}

// =================================================================================================
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"MyCustomCell";

    MyCustomCell *cell = (MyCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        UIViewController *c = [[UIViewController alloc] initWithNibName:CellIdentifier bundle:nil];
        cell = (MyCustomCell*)c.view;
        [c release];
    }

    return cell;
}

- (void)tableView:(UITableView *)tableView willDi开发者_开发问答splayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    MyCustomCell* theCell = (MyCustomCell*)cell;

theCell.theTextView.text = @"Label My Label";
}

// =================================================================================================
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100; // -- In fact it's dynamic
}

Using that code, I have a strange behaviour on the simulator (iOS 4.2). I have just one cell (grouped tableview). When I scroll the list to make the cell disapear at the top of the screen, and then when I let it free, instead of just scrolling down smoothly, the list suddenly reappears on the screen as if I had never scrolled it and then scroll a little bit (around 25px, to the top of my TextView in fact) to the top.

If I remove or comment theCell.theTextView.text = @"Label My Label"; then there are no problem enad the list acts as usual. The probelm does not exist if I only scroll a little bit to the top so the cell does not disapear. The problem is the same if I have many rows and make the first cell go over the top.

The TextView is inside the UITableCellView, and the textview is large enough to display the texte as a one-line text.

Can you see where is the problem ?

Please just comment to ask for additional informations or just suggestions if you don't have the answer, to let other people see there is not yet an answer on this question.

Thank you for your help.


The problem was that the "Scrolling enabled" property of the TextView was not set. Setting this property to "ON" and the problem is gone...

0

精彩评论

暂无评论...
验证码 换一张
取 消