我正在使用以下代码来获取视频的属性日期,但问题是它返回为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;
}
}
如果您对YYYY-MM-DD HH:MM:SS ±HHMM
格式感到满意,可以使用-description
的NSDate
方法。在你的情况下,那将是:
CamDurationLabel.text = [CamDuration description];
如果您想要更灵活一点,请查看NSDateFormatter
类。 iOS 4.0+有一个很好的类方法:
NSDate *today = [NSDate date];
NSString *formattedDate = [NSDate localizedStringFromDate:today dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle];