English 中文(简体)
参考书目
原标题:UITableView Section Titles Causing Table View Slowness

I have a UITableView that loads entities from Core Data using a NSFetchedResultsController. The fetch request is currently using a batch size to keep memory overhead under control as there are about 1000 rows being returned from the fetch. After hooking all this up, the table view was really fast.

现在,我的问题是,我想在表态中增加一组标题。 我已采用了必要的代表方法,但似乎在“条码”表:标题ForHeaderIn Section:

是否有更好的办法填充该节标题,或者,更糟的是,是否可把标题的加添到与实际桌子一样的用户卷上?

值得注意的一些事项:

  • I am telling the fetch request to pre-fault dateOfFlight using the setPropertiesToFetch: method.
  • The fetch request has a batch limit of 25.
  • The fetch request has no fetch limit.
  • I do not need section index titles. For sectionIndexTitlesForTableView:, I am returning Nil;
  • There are about 1000 entities returned from the fetch and, because we re grouping by a localized date, there are about 700 sections.

对于其价值而言,本条准则一用在标题上:

/**
 * We override this method from the base class because we need to format the date
 * prior to it being displayed in the UITableViewSection.
 * @author Jesse Bunch
 **/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    Flight *cellEntity = (Flight *)[[sectionInfo objects] objectAtIndex:0];

    if (cellEntity) {
        return [cellEntity.dateOfFlight localizedLongDateString];
    }

    return L(@"Unknown Date");

}

-

Edit

我的确通过从款次名称而不是实体本身对日期进行格式化,实现了比较高的速度:

/**
 * We override this method from the base class because we need to format the date
 * prior to it being displayed in the UITableViewSection.
 * @author Jesse Bunch
 **/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    static NSDateFormatter *dateFormatter;
    if(nil == dateFormatter) {
        dateFormatter = [[NSDateFormatter alloc] init];
        dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss ZZ";
    }

    id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    NSDate *sectionDate = [dateFormatter dateFromString:sectionInfo.name];  

    if (sectionDate) {
        return [sectionDate localizedLongDateString];
    }

    return L(@"Unknown Date");

}
问题回答

您是否考虑逐步装出和显示数据?

我指的是:你装上一组数据并显示Nrows(带有N <<1000);如果用户浏览量过去是最后一行,则会装上更多的数据,显示更多的浏览量(以及更多的部分)。

我不相信这种做法能够解决你的问题(很可能是,在经过一些拖车后,这种观点会放慢所有的速度),但我认为,你可以让它尝试......可能的话,用户的经验也会从中获益(因为速度缓慢)。

If you are interested, you can give a look at EGOTableViewPullRefresh which implements a similar mechanism for "pull down to reload". This could be useful for detecting the scroll past the last row.





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签