开发者

display ALAssetPropertyDate in UILabel using AssetsLibrary in objective C

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜