开发者

display ALAssetPropertyDate in UILabel using AssetsLibrary in objective C

开发者 https://www.devze.com 2023-01-20 02:31 出处:网络
i\'m using the following code to get the property date of the video but the problem is it return as NSDate and when I tried to assign it to UILabel.text in UITableView the program crashes. Can anyone

i'm using the following code to get the property date of the video but the problem is it return as NSDate and when I tried to assign it to UILabel.text in UITableView the program crashes. Can anyone help me?

 void (^assetEnumerator)(struct ALAsset *,NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
            if开发者_JAVA百科(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;

         }
}


If you're happy with the format YYYY-MM-DD HH:MM:SS ±HHMM, you can use the -description method of NSDate. In your case, that would be:

CamDurationLabel.text = [CamDuration description];

If you'd rather a bit more flexibility, look into the NSDateFormatter class. iOS 4.0+ has a nice class method:

NSDate *today = [NSDate date];
NSString *formattedDate = [NSDate localizedStringFromDate:today dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle];
0

精彩评论

暂无评论...
验证码 换一张
取 消