2014-11-11 3 views
0

그래서 내 앱에 다운로드 관리자가 있습니다. 나는 오늘 그것을 위로하기 위해 나 자신에 그것을 가져 갔다.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; 
    } 

고맙습니다.

답변

1

나는 이것을 시험해 보았고 어떤 이유로 numberOfLines를 2로 설정해도 나에게 도움이되지 못했지만 2 이상으로 설정하거나 0으로 설정하면 효과적이었다.

두 문자열을 올바르게 형식화해야합니다. 이

[NSString stringWithFormat:dateString, @"%@", [self formattedFileSize:fileSize]] 

그것은 다음과 같이해야한다,

[NSString stringWithFormat:@"%@\n%@", dateString, [self formattedFileSize:fileSize]]; 
+0

그래도 cell.detailTextLabel.numberOfLines = 2를 사용해 보았습니다. 나는 이것을 올바르게 설정하는 방법을 알아야 할 것 같습니다. cell.detailTextLabel.text = [NSString stringWithFormat : dateString, @ "% @", [self formattedFileSize : fileSize]]. 해당 날짜 문자열이 있으면 날짜가 표시되지만 파일 크기 코드는 표시되지 않습니다. – ChrisOSX

+0

@ChrisOSX, 3 살이시겠습니까? 0을 시도해보고 효과가 있는지 확인하십시오. – rdelmar

+0

나는 0에서 10 lol 운을 시도했다. – ChrisOSX

0

이를 파악, 올바른 구문이 아닙니다. 그냥 문자열의 형식으로 조정해야했습니다.

cell.detailTextLabel.text = [NSString stringWithFormat:@"%@\n%@", dateString, [self formattedFileSize:fileSize]]; 

이 답변을 게시하면 페이지가 새로 고쳐지고 rdelmar가 올바른 구문을 나타내는 업데이트 된 게시물에서도 정확하다는 것을 알 수 있습니다.

크레딧을 주셔서 감사 드리며 도움을 주신 데 대해 감사드립니다.

관련 문제