我不確定我是否正確地解答了我的問題,所以這裏是詳細信息。 我正在使用UITableView來顯示可用字體的列表。列表被dsiplayed時, 一次只顯示大約12行,因此如果先前選擇的字體尚未顯示,則在首次顯示視圖時無法選擇它。如何選擇尚未顯示的UITableView行?
我希望在出現視圖時讓單元格選中並顯示在列表中央。但是,由於根據需要只的UITableView加載數據,這是最好的,我可以得到:
EDITED 我已經試過,但它不工作(細胞只簡單地選擇同時滾動):
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell.textLabel setText:[fontArray objectAtIndex:indexPath.row]];
[cell.textLabel setFont:[UIFont fontWithName:[fontArray objectAtIndex:indexPath.row] size:16]];
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
//select the cell/row if it matches the current font
if([cell.textLabel.text isEqualToString:currentFontName]){
cell.selected=YES;
}
NSLog(@"returning cell %@",cell.textLabel);
return cell;
}
FWIW,不重複使用單元格是創建滾動可怕表格的好方法。這聽起來像是細胞重新使用時,錯誤並未重置細胞狀態。 – smparkes 2012-02-25 19:33:27