1

ここに画像の説明を入力

上記のスクリーン ショットのように、Tableview の各セルに 2 つの値を表示したいことがわかります。同じクラスのセルのこれらのラベルに表示したいデータがあればそれを行うことができますが、私にとっての問題は、(NSDocumentDirectory、NSUserDomainMask、YES を使用して、他のビューまたは他のクラスからこれらの両方のラベルを取得しようとしていることです。 )したがって、スクリーンショットが示すように1つの値を表示することに成功しましたが、現在のデータと時間表示で構成される他の部分はまだ問題です。

NSString *fina = [NSString stringWithFormat:@"%@",mySongname];
NSArray  *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docsDir  = [dirPaths objectAtIndex:0];
    NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"MyRecordings"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:soundFilePath])
        [[NSFileManager defaultManager] createDirectoryAtPath:soundFilePath withIntermediateDirectories:NO attributes:nil error:nil];
    soundFilePath = [soundFilePath stringByAppendingPathComponent:fina];
    recordedTmpFile = [NSURL fileURLWithPath:soundFilePath];
    recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
    [recorder setDelegate:self];
    [recorder prepareToRecord];
    [recorder record];
    [recordSetting release];

コードの上記の部分は正常に動作し、私のスクリーンショーであるTableview Cellに値を表示します。同じ関数で、以下のコードを使用してTableview CellのUILabelである赤い部分で表示するデータを取得しようとしています。

 NSDate* now = [NSDate date];
 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
 [dateFormatter setDateFormat:@"dd:MMM:YY_hh:mm:ss a"];
 NSString *file= [dateFormatter stringFromDate:now];
 NSLog(@"myfinaldate:%@",file);

ここで、この日付値を上記と同じディレクトリに保存し、 UITableview の赤い部分を表示したいと考えています。ここに、このTableviewを使用してこれらのドキュメントディレクトリの値を取得するコードがあります。

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentPath = [documentsDirectory stringByAppendingPathComponent:@"MyRecordings"];
directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath:documentPath];
      NSLog(@"file found %i",[directoryContent count]);
[directoryContent retain];
[self.tableView reloadData];
  }

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
static NSInteger StateTag = 1;
static NSInteger CapitalTag = 2;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    UILabel *capitalLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 2, 80, 20)];
    //capitalLabel.text=@"mydata";
    capitalLabel.backgroundColor=[UIColor redColor];
    capitalLabel.tag = CapitalTag;
    [cell.contentView addSubview:capitalLabel];
    [capitalLabel release];

    UILabel *stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 22, 310, 20)];
    stateLabel.tag = StateTag;
    [stateLabel setFont:[UIFont systemFontOfSize:14]];
    stateLabel.adjustsFontSizeToFitWidth=YES;
    [cell.contentView addSubview:stateLabel];
    [stateLabel release];

}
UILabel * stateLabel = (UILabel *) [cell.contentView viewWithTag:StateTag];
//UILabel * capitalLabel = (UILabel *) [cell.contentView viewWithTag:CapitalTag];

stateLabel.text = [directoryContent objectAtIndex:indexPath.row];
//capitalLabel.text = [directoryContent1 objectAtIndex:indexPath.row];
  return cell;
 }

今、私は問題を要約しようとしています。日付と時刻の値を同じディレクトリに保存する方法と、UITableview セルの赤い部分にここに表示する方法は? capitalLabel は、問題である日付と時刻を表示するセルの Redpart です。stateLabel all ready は値を表示します。このラベルで問題ありません。どんな助けでも大歓迎です。

4

1 に答える 1

0

これを行うだけで....

NSCachesDirectoryに設定できますNSDocumentDirectory

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:yourComponent];
//    NSLog(@"Path : %@",writableDBPath);

NSMutableDictionary *plistArr = [[NSMutableDictionary alloc] initWithContentsOfFile:writableDBPath];
于 2012-12-05T12:12:18.957 に答える