使用目标C中的AssetsLibrary在UILabel中显示ALAssetPropertyDate

问题描述 投票:0回答:1

我正在使用以下代码来获取视频的属性日期,但问题是它返回为NSDate,当我尝试将其分配给UILabel.text中的UITableView时程序崩溃。谁能帮我?

 void (^assetEnumerator)(struct ALAsset *,NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
            if(result != nil){
                //[Asset addObject:result];

                  if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
                    // asset is a video


                    [Asset addObject:result];
                    NSString  *CamDuration = [result valueForProperty:ALAssetPropertyDate];

                }
            }
        };

    - (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] autorelease];

            CGRect frame = CGRectMake(125, 12, 200, 19);
            UILabel *CamDurationLabel = [[UILabel alloc] initWithFrame:frame];
            CamDurationLabel.tag = 1;
            [cell.contentView addSubview:CamDurationLabel];
            CamDurationLabel.text = CamDuration;

         }
}
iphone objective-c
1个回答
0
投票

如果您对YYYY-MM-DD HH:MM:SS ±HHMM格式感到满意,可以使用-descriptionNSDate方法。在你的情况下,那将是:

CamDurationLabel.text = [CamDuration description];

如果您想要更灵活一点,请查看NSDateFormatter类。 iOS 4.0+有一个很好的类方法:

NSDate *today = [NSDate date];
NSString *formattedDate = [NSDate localizedStringFromDate:today dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle];
© www.soinside.com 2019 - 2024. All rights reserved.