慢滚动的UITableView [英] slow scrolling of UITableView
本文介绍了慢滚动的UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
UIImage in uitableViewcell slowing scrolling table
我的表视图数据与plist文件将从服务器下载。但是在用户滚动表后,滚动很慢!这是我的代码:
//这是我从服务器加载的plist代码
NSURL * url = [NSURL URLWithString:@http://example.com/news.plist];
titles = [[NSArray arrayWithContentsOfURL:url] retain];
tableview:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return titles.count;
return subtitle.count;
}
//自定义表视图单元格的外观。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @Cell;
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@bg.gif]];
//配置单元格。
NSUInteger row = [indexPath row];
cell.textLabel.text = [titles objectAtIndex:row];
cell.textLabel.textColor = [UIColor darkGrayColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.text = [subtitle objectAtIndex:row];
cell.detailTextLabel.numberOfLines = 6;
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
//细胞的渐变BG
UIImage * image = [UIImage imageNamed:@bg2.gif];
UIImageView * imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleToFill;
cell.backgroundView = imageView;
[imageView release];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
tableView.separatorColor = [UIColor lightTextColor];
return cell;谢谢你告诉我我的问题是什么。 >
解决方案提供这项服务:
- (void)viewDidLoad {
[super viewDidLoad];
tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@bg.gif]];
tableView.separatorColor = [UIColor lightTextColor];
}
//自定义表视图单元格的外观。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @Cell;
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
//在此处执行所有设置,而不是如果单元格出列。
cell.textLabel.textColor = [UIColor darkGrayColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
//细胞的渐变BG
UIImage * image = [UIImage imageNamed:@bg2.gif];
UIImageView * imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleToFill;
cell.backgroundView = imageView;
[imageView release];
cell.detailTextLabel.numberOfLines = 6;
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
//配置单元格。
NSUInteger row = [indexPath row];
cell.textLabel.text = [titles objectAtIndex:row];
cell.detailTextLabel.text = [subtitle objectAtIndex:row];
return cell;
}
Possible Duplicate:
UIImage in uitableViewcell slowdowns scrolling table
I filled my table view data with plist file which will download from a server . but after user scrolls the table the scrolling is very slow ! this is my code :
//this is my plist code that load from server
NSURL *url = [NSURL URLWithString:@"http://example.com/news.plist"];
titles = [[NSArray arrayWithContentsOfURL:url] retain];
tableview :
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return titles.count;
return subtitle.count;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.gif"]];
// Configure the cell.
NSUInteger row = [indexPath row];
cell.textLabel.text = [titles objectAtIndex:row];
cell.textLabel.textColor = [UIColor darkGrayColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.text = [subtitle objectAtIndex:row];
cell.detailTextLabel.numberOfLines = 6;
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
//gradiant BG for cells
UIImage *image = [UIImage imageNamed:@"bg2.gif"];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
imageView.contentMode = UIViewContentModeScaleToFill;
cell.backgroundView = imageView;
[imageView release];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
tableView.separatorColor = [UIColor lightTextColor];
return cell;
}
Thank you for telling me what's is my problem
解决方案 Give this a go:
- (void) viewDidLoad {
[super viewDidLoad];
tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.gif"]];
tableView.separatorColor = [UIColor lightTextColor];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Do all your desgin settings here, not if the cell gets dequeued.
cell.textLabel.textColor = [UIColor darkGrayColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
//gradiant BG for cells
UIImage *image = [UIImage imageNamed:@"bg2.gif"];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
imageView.contentMode = UIViewContentModeScaleToFill;
cell.backgroundView = imageView;
[imageView release];
cell.detailTextLabel.numberOfLines = 6;
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
NSUInteger row = [indexPath row];
cell.textLabel.text = [titles objectAtIndex:row];
cell.detailTextLabel.text = [subtitle objectAtIndex:row];
return cell;
}
这篇关于慢滚动的UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文