2011-12-24 40 views
0

我正在做一些关于flickr照片处理的培训..我想显示最流行的地方和相关照片。目前,该应用程序有一个TabBarController,并且每个选项卡都有一个导航控制器作为“起点”。故事板是:[TableView of places] - > [Table View of photos] - > [Scroll View of the image] 现在,我想让用户有机会切换到地图表示而不是表格视图,没有做任何进一步的细分。UINavigationController + UITabBarController + UISegmentedControl与TableView/MapView

我认为最好的办法是使用UISegmentedControl,所以我用这个布局[link to image]。当表格可见时,地图是隐藏的(反之亦然)。

仅使用表格表示法,我使用了TableViewController。通过这个修改,我分类了一个UIViewController,并且我实现了“手工”两个表协议(delegatedatasource),我连接了网点,但是现在表滚动的帧率很低

我问flickr最流行的地方,我拆分JSON,并获得NSDictionary的NSArray,我称之为'地方'(每个字典=地方)。然后,我按国家分段分割这些地方:国家列表(按字母顺序排列)被称为'sortedCountries'。然后,我创建了一个名为'placesByCountry'的NSDictionary(key = country/value =该国家的地方数组)。

这里是一些代码,我写道:

- (NSArray*)addressForPlace:(NSDictionary*)place { 
    return [[place objectForKey:@"_content"] componentsSeparatedByString:@", "]; } 

- (NSString *)countryForSection:(NSInteger)section { 
return [self.sortedCountries objectAtIndex:section]; } 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    return [self countryForSection:section]; } 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return [self.placesByCountry count]; } 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    NSString *country = [self countryForSection:section]; 

    NSArray *placesByCountry = [self.placesByCountry objectForKey:country]; 

    return [placesByCountry count]; } 

- (UITableViewCell *)tableView:(UITableView *)tableViewLocal cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Top Place Cell"; 

    UITableViewCell *cell = [tableViewLocal dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 

    NSString *country = [self countryForSection:indexPath.section]; 
    NSArray *placesByCountry = [self orderedPlacesForCountry:country]; 

    NSDictionary *place = [placesByCountry objectAtIndex:indexPath.row]; 

    NSArray *address = [self addressForPlace:place]; 
    cell.textLabel.text = [address objectAtIndex:0]; 

    NSMutableString *remainigAddres = [NSMutableString string]; 
    for (NSString *s in address) { 
     if ([address indexOfObject:s] != 0) { 
      if ([address indexOfObject:s] != [address indexOfObject:[address lastObject]]) 
       [remainigAddres appendFormat:@"%@, ", s]; 
      else 
       [remainigAddres appendString:s]; 
     } 
    } 
    cell.detailTextLabel.text = remainigAddres; 


    return cell; } 

这是我的问题的正确的方法?我应该怎么做提高表演?我刚刚检查过单元格标识符,而不是要下载的图像!唯一的异步队列发生在表的初始人口(当我查询flickr时)。

编辑: 也许我发现问题...表滚动具有低帧率,可以看到,在tableView:cellForRowAtIndexPath:方法中,我调用另一个方法,orderedPlacesForCountry :.这种方法对即时进行排序:

- (NSArray*)orderedPlacesForCountry:(NSString*)country { 
    NSArray* places = [self.placesByCountry objectForKey:country]; 
    if (DEBUG_LOG_ACTIVE) NSLog(@"places: %d", [places count]); 

    NSMutableArray* cities = [NSMutableArray array]; 
    for (NSDictionary* place in places) { 
     [cities addObject:[[self addressForPlace:place] objectAtIndex:0]]; 
    } 
    if (DEBUG_LOG_ACTIVE) NSLog(@"cities: %d", [cities count]); 

    NSArray *sortedCities = [cities sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; 
    if (DEBUG_LOG_ACTIVE) NSLog(@"sorted cities: %d", [sortedCities count]); 

    NSMutableArray *sortedPlaces = [NSMutableArray arrayWithCapacity:[places count]]; 

    for (NSString* city in sortedCities) { 
     //per ogni città cerco in places quel place 
     for (NSDictionary* place in places) { 
      if ([[[self addressForPlace:place] objectAtIndex:0] isEqualToString:city]) 
       //e lo aggiungo a sorted 
       [sortedPlaces addObject:place]; 
     } 
    } 

    if (DEBUG_LOG_ACTIVE) NSLog(@"sorted places: %d", [sortedPlaces count]); 

    return sortedPlaces; } 

如果我没有一个国家的地方进行排序,表滚动是好的..所以我会尝试在刚开始的时候进行排序数据被加载,而不是在滚动时“即时”。

+0

这听起来像是正确的方法,我不知道为什么你得到一个低帧率你能给我们更多的细节,你是什么意思?我怀疑如果刷新tableview时出现问题,你会在滚动表格时做一些计算繁重的工作(可能更新隐藏地图?) – 2011-12-24 18:18:32

+0

@ScottSherwood问题已更新;) – Ciampo 2011-12-24 20:54:46

回答

0

随着你给我们的小信息,我认为让你的桌子变慢的代码片段就是你的单元格,你是在单元格中显示某种图像吗?如果是这样,你是否同步下载它们?你在单元格内插入了webviews还是大文本?

这是一种可以使桌面运行速度变慢的事情,请添加更多信息以帮助您!

+0

问题已更新;) – Ciampo 2011-12-24 20:55:32

相关问题