0
我有一個UITableView有7行,每行包含文本和.png圖像。當我添加代碼來設置每行圖片並在模擬器中運行應用程序時,我會遇到很長的加載時間。表視圖加載性能問題
我懷疑性能問題的原因是我的圖像尺寸太大,我正在將我的圖像縮放到合適的像素尺寸。但是,我想確保我的代碼中有任何不同的工作可以進一步優化性能。我的代碼中有什麼我應該做的不同嗎?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *c = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!c)
{
c = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"Cell"];
}
//adds text to table view
[[c textLabel] setText:[categoryNames objectAtIndex:[indexPath row]]];
[[c textLabel] setTextColor:[UIColor whiteColor]];
//add pictures to table view
NSString *path = [[NSBundle mainBundle] pathForResource:[categoryURLs objectAtIndex:[indexPath row]] ofType:@"png"];
[[c imageView] setImage:[UIImage imageWithContentsOfFile:path]];
return c;
}