小编Dav*_*d L的帖子

如何在UITableView中获取所有单元格

假设我有一个有多行的UITableView.我希望在某个时间点将所有UITableViewCells作为NSArray.我试过了

[tableView visibleCells] 
Run Code Online (Sandbox Code Playgroud)

但是这种方法存在问题:我不能拥有当前屏幕中当前不存在的所有单元格.所以我转向另一种方法:

-(NSArray *)cellsForTableView:(UITableView *)tableView
{
    NSInteger sections = tableView.numberOfSections;
    NSMutableArray *cells = [[NSMutableArray alloc]  init];
    for (int section = 0; section < sections; section++) {
        NSInteger rows =  [tableView numberOfRowsInSection:section];
        for (int row = 0; row < rows; row++) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];   // **here, for those cells not in current screen, cell is nil**
            [cells addObject:cell];
        }
    }
    return cells;
}
Run Code Online (Sandbox Code Playgroud)

但似乎这种方法仍然无法获得那些未在屏幕上显示的细胞.谁可以帮我这个事?

uitableview ios

32
推荐指数
3
解决办法
5万
查看次数

CLPlacemark.locality,如果设备语言不同,则值会更改

我使用CLGeocoder将CLLocation从经度/纬度解码为地名.它工作正常.但是仍然有一件事困扰着我.当我将设备语言设置为英语时,代码的结果如下:

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation{
       /* We received the new location */
       NSLog(@"Latitude = %f", newLocation.coordinate.latitude);
       NSLog(@"Longitude = %f", newLocation.coordinate.longitude);
       [self.geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray* placemarks, NSError* error){
           MKPlacemark *placemarker = [placemarks objectAtIndex:0];
           NSLog(@"%@",placemarker.locality);
       }];
      [self.locationManager stopUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)

}

以英文显示,例如:chengdu.

当我将设备语言更改为中文时,

placemarker.locality
Run Code Online (Sandbox Code Playgroud)

返回中文字符值.

但我真正想要的是它总会返回一个英文字符值(没有中文字符值).我猜这是与语言环境有关的东西.任何人都可以帮忙吗?谢谢.

ios clgeocoder

7
推荐指数
2
解决办法
3836
查看次数

标签 统计

ios ×2

clgeocoder ×1

uitableview ×1