简体   繁体   中英

how to add smooth scroll to UITbaleview when we adding new row to table view

i am getting images with messages from .net webserver by giving xml input.

that's working fine.

i am sending request for every 3 sec and if any new messages and images are there i just add those messages and images to the array and reload the table view.

That is also fine,But what i need is when i reload table view when ever there is new messages that will be displayed on table view by smooth scrolling the existing row.

same as twitter.

can any one please help me.

Thank u in advance.

如果您知道新添加的行的indexPath ,则可以使用UITableView的以下功能滚动到带有动画的新行(平滑效果)。

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated

Instead Of completely reloading the table, you should call insertRowsAtIndexPaths:withRowAnimation:

The second option will let you specify how you want it animated

(this will also be much more efficient than reloading all the data every time)

You can do something like the following: (this makes the assumptions that recievedImageFrom server will be called after the data has already been loaded into the data source object. Also, myDataSourceArray is the array where the data is being stored for the table and myTableView is the UITableView.

-(void)recievedImageFromServer
{
    NSUInteger row = [myDataSourceArray count]-1; // This can also be set to 0 if you want
                                                // to insert at the top of the table

    NSIndexPath* newIndex = [NSIndexPath indexPathWithIndex:row];
    [myTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndex]
                       withRowAnimation:UITableViewRowAnimationTop];
}

It will then request the cell from its data source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM