그래서 내 앱에 다운로드 관리자가 있습니다. 나는 오늘 그것을 위로하기 위해 나 자신에 그것을 가져 갔다.UITableViewCellStyleSubtitle에 여러 줄을 표시하는 방법
UITableViewCellStyleSubtitle을 구현했으며 올바르게 표시하고 있습니다.
두 줄 이상을 추가하고 싶습니다. 지금은 파일 크기 또는 형식이 지정된 날짜를 선택하는 데 막혔습니다.
어떻게 둘 다합니까? 즉
Cell Title
Date: (followed by file size) or
File Size:
다음은 관련 코드입니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [(UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier] autorelease];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
}
// Configure the cell.
cell.textLabel.text = [directoryContents objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryNone;
[cell.layer setBorderColor:[UIColor colorWithRed:30/255.0 green:30/255.0 blue:30/255.0 alpha:1.0].CGColor];
[cell.layer setBorderWidth:1.5f];
cell.textLabel.numberOfLines = 0;
//Get file size
NSError *error;
NSString *fileName = [directoryContents objectAtIndex:indexPath.row];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"my folder"];
path = [path stringByAppendingPathComponent:fileName];
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
NSInteger fileSize = [[fileAttributes objectForKey:NSFileSize] intValue];
//Setting the date
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"my folder"];
filePath = [filePath stringByAppendingPathComponent:fileName];
NSDate *creationDate = nil;
NSDictionary *attributes = [fileManager attributesOfItemAtPath:filePath error:nil];
creationDate = attributes[NSFileCreationDate];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
NSString *dateString = [dateFormatter stringFromDate:creationDate];
/////This is where I need to blend the dateString with the file size//////
cell.detailTextLabel.text = [NSString stringWithFormat:dateString, @"%@", [self formattedFileSize:fileSize]];
cell.detailTextLabel.numberOfLines = 2;
return cell;
}
고맙습니다.
그래도 cell.detailTextLabel.numberOfLines = 2를 사용해 보았습니다. 나는 이것을 올바르게 설정하는 방법을 알아야 할 것 같습니다. cell.detailTextLabel.text = [NSString stringWithFormat : dateString, @ "% @", [self formattedFileSize : fileSize]]. 해당 날짜 문자열이 있으면 날짜가 표시되지만 파일 크기 코드는 표시되지 않습니다. – ChrisOSX
@ChrisOSX, 3 살이시겠습니까? 0을 시도해보고 효과가 있는지 확인하십시오. – rdelmar
나는 0에서 10 lol 운을 시도했다. – ChrisOSX