我发现这个方法叫做- (void)prepareForReuse
.我阅读了该文档,但我不明白如何使用它.
当我滚动我的tableview,它被卡住,或有慢滚动,我打算使用prepareForReuse
.有人可以指点我一个很好的教程或给我一些示例代码,以便我可以学习.
对不起,我没有任何代码来证明我的工作.
我有一个UITableView,在200个部分中有大约400个单元格,并且在响应用户交互(滚动,选择单元格)时有点迟钝.我已经确保检索单元格和标题视图的方法在运行时最小化,并且我不认为我做任何与众不同的事情让它变慢.单元格和标题只有一个背景图像和文本.有没有其他人有这样的问题,你知道有什么办法让它运行得更快一点吗?
编辑:我正在提供赏金,因为我很想得到一些有用的反馈.我不认为答案在于我的代码中的问题.相反,我正在寻找重新设计UITableView的策略,以便它运行得更快.我完全愿意添加新代码,我期待听到你们要说的话.
在模拟器和我的设备(iPhone 4)上都观察到了低迷.这是我的实现viewForHeaderInSection
和cellForRowAtIndexPath
,这是唯一UITableViewDelegate
实现非常重要的方法.我正在重用单元格和标题视图.
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger) section
{
HaikuHeaderView* view= [m_sectionViews objectAtIndex:section];
NSMutableArray* array= [m_haikuSearch objectAtIndex:section];
Haiku* haiku= [array objectAtIndex:0];
[view.poetLabel setText:[haiku nameForDisplay]];
return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.backgroundView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell gradient2.png"]];
// (Set up a bunch of label attributes …
Run Code Online (Sandbox Code Playgroud) 我有一个带有大图像的桌面视图,可以填充单元格,并根据图像大小设置行高.不幸的是,当滚动到下一个单元格时,表格严重抖动.
有人告诉我,如果在将行高度和图像加载到表格之前缓存行高度,我的tableview将滚动得更顺畅.我的所有数据都存储在plist中.
我如何去缓存一些东西?代码是什么样的,它在哪里?
谢谢!
这是我加载图像的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *detailTableViewCellIdentifier = @"Cell";
DetailTableViewCell *cell = (DetailTableViewCell *)
[tableView dequeueReusableCellWithIdentifier:detailTableViewCellIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DetailTableViewCell" owner:self options:nil];
for(id currentObject in nib)
{
cell = (DetailTableViewCell *)currentObject;
}
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *MainImagePath = [Path stringByAppendingPathComponent:([[appDelegate.sectionsDelegateDict objectAtIndex:indexPath.section] objectForKey:@"MainImage"])];
cell.mainImage.image = [UIImage imageWithContentsOfFile:MainImagePath];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我也使用以下方法计算行高:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
AppDelegate *appDelegate = (DrillDownAppAppDelegate *)[[UIApplication …
Run Code Online (Sandbox Code Playgroud) 我想在Twitter应用程序中实现atebits使用的相同技术,以实现非常快速的UITableView滚动,
http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/
但是,由于Tweetie被Twitter购买,因此atebits已经不复存在,示例代码已经消失,以及网站的所有css.
有没有人有一个示例代码的副本或实现这种将UITableViewCell绘制到一个视图中的方法的不同资源?