views:

22

answers:

1

hi, 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 assigned it to UILabel.text in UItable the program crash on me. Can anyone help me?

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;
    

    }

A: 

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];
Sedate Alien
hi, thanks for the great tip but how do i display them on a uitable? currently i have 2 video but both the video displayed in uilabel is the same(the latest video date) for each table cell. how do i do this?Thanks in advance
tan