自动滚动的UITableView问题
问题描述:
我用下面的代码进行自动滚动的UITableView自动滚动的UITableView问题
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [DataArray count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"CustomTableCell";
CustomTableCell *cell = (CustomTableCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[[CustomTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
}
if(isAutoScrollEnabled)
[DataTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
cell.Time.text = [[DataArray objectAtIndex:indexPath.row]objectForKey:@"CurrentTime"];
cell.SerialNo.text = [NSString stringWithFormat:@"%d",indexPath.row+1];
return cell;
}
但每次我在tableview中加载数据时fluctates我的tableview。有没有解决方法?
任何人都可以帮助我吗?
在此先感谢......
答
你想要什么?
平滑滚动下来? 或 滚动到新的细胞位置?
第一种情况(平滑滚动)应该使用NSTimer。 第二种情况(到新细胞位置)应该覆盖UITableView [updateData]
答
我不确定你到底在说什么。但我会说,在你的cellForRowAtIndexPath中调用scrollToRowAtIndexPath看起来可能会导致问题。你正在做的是告诉它每次产生一个单元格时滚动。这看起来不正确。
我也不得不怀疑,如果你真的想要动画滚动。
+0
是的,我想显示动画自动滚动tableview。 WHere我可以在我的代码中使用scrollToRowAtIndexPath功能。 – dragon 2010-07-26 07:32:26
你可以发布一些关于平滑向下滚动的代码吗? – dragon 2010-07-26 11:19:03
对不起,我做了一个繁重的工作,所以我无法编写一些代码。 但是,我解释了这个... 使用NSTimer间隔一段时间。 在时间事件(选择器) U可以在UITableView上的UIScrollView 或 (scrollToRowAtIndexPath:atScrollPosition:animated :)上滚动您的视图(scrollRectToVisible:animated :)。 祝你好运。 – TopChul 2010-07-27 05:09:03