我用plist文件填充了我的表视图数据,该文件将从服务器下载。但是在用户滚动表格之后,滚动速度非常慢!这是我的代码:
//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;
}
感谢您告诉我我的问题是什么
答案 0 :(得分:3)
问题很可能是您在bg2.gif
内加载图片(例如bg.gif
或tableView:cellForRowAtIndexPath:
)。我首先尝试在构造函数或表视图控制器的单独方法中加载这些图像,将它们存储在实例变量中,然后在需要时重新使用它们。
答案 1 :(得分:2)
放手一搏:
- (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;
}
答案 2 :(得分:1)
删除tableView
中- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
的所有函数/方法调用,您应该在tableView
或-viewDidLoad
中配置-loadView
。
为了提高滚动速度,建议您查看以下内容:http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/。