2017-04-05 5 views
0

私のiOSアプリケーションプロジェクトでは、文書ディレクトリのファイル構造に保存された録音されたaudio.cafファイルを作成し、 TableViewの連続するTableViewCellにリストされます。 タイトル「 」と字幕として作成されたファイルの一意の「オーディオファイル名」と「NSDate」の両方を、各セル内で連続して表示します。 特定のパスで記録されたファイルを作成するために使用されるコードは、Mainviewcontrollerにあります。ファイル名とNSDateStringでTableViewのタイトルとして一意のファイル名を表示する(ヘルプが必要です)

NSArray *pathComponents = [NSArray arrayWithObjects: 
            [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], 
            _filePath, 
            nil]; 
     newURL = [NSURL fileURLWithPathComponents: pathComponents]; 
     _filePath = [documentsDirectory stringByAppendingPathComponent:@"audio %@ %@.caf"]; 
     // Initiate and prepare the recorder 
     //NSInteger count = 0; 
// To create the date string <--- 
     NSString *dateString; 
     NSDate *aDate = [NSDate date]; 
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
     [dateFormatter setDateFormat:@"yyyy-MM-dd"]; 
     dateString = [dateFormatter stringFromDate:aDate]; 
     NSLog(@"datestring %@",dateString); 


     int count = 0; 
     int arrayCount = [audioFileArray count]; 



      documentsDirectory = [pathComponents objectAtIndex:0]; 

      NSError *error = nil; 
// To create the recorded file name and date combined <--- 
      _audioFileArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error]; 
      filename = [NSString stringWithFormat:@"audio %@ %@.caf", dateString,[NSNumber numberWithFloat:[_audioFileArray count]]]; 
        count ++; 

私もファイル「数」が「NSDate」の前に来るが、これは、それはすなわち動作することを唯一の方法であるように、コードを再配置したいです。 _audioFileArrayのカウントビットの前のDateString!

そして、のUITableView fileViewControllerでファイル名のテキストを表示するビットです:UITableViewCellsに表示私の配列の

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *simpleTableIdentifier = @"simpleTableItem"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:simpleTableIdentifier]; 
} 
NSString *name = [_filteredArray objectAtIndex:indexPath.row]; 
//add the text display that is drawn from the array list 
cell.textLabel.text = name; 
cell.textLabel.text = [_filteredArray objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ is the recorded date", name]; 
return cell 

タイトルは、この図に示されています。私がやって探しています何

Table view cells comparison

は、各セルのタイトルの日付(作成)の部分を削除し、代わりにdetailtextLabelタイトルにそれを再配置です。 メインビューコントローラと詳細ビューコントローラ で同時に呼び出すことができる(または利用する)別のNSDateクラスを作成することでこれを行うことができますが、まだこのアプローチを試していません。

たとえば、JSONまたはplistを使用して保存された各ファイルプロパティの辞書を作成すると、これがうまく機能します。 これに関するお手伝いがあれば幸いです。この投稿にもっと明快さが必要な場合は、私にも教えてください。

最後に、フォーラムでこの問題の簡潔な解決策を探し出しましたが、まだ解決策が見つかりませんでした。

多くのありがとうございます。

答えて

0

私のコードを見ても、日付文字列がnilまたは空の値を返すようです。 はあなたのコードを置き換える:

このコードで
NSString *dateString; 
NSDate *aDate = [NSDate date]; 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd"]; 
dateString = [dateFormatter stringFromDate:aDate]; 
NSLog(@"datestring %@",dateString); 

NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
[formatter setDateFormat:@"dd-MM-yyyy"]; 
NSDate *currentDate = [NSDate date]; 
NSString *dateString = [formatter stringFromDate:currentDate]; 
NSLog(@"datestring %@",dateString); 

+0

..あなたに感謝私が知っているok..let。その作業かどうか。 – Sommm

+0

@Somme。あなたの以前の投稿に戻ります。私の例で一緒にハックしたNSDateフォーマッタは、実際に日付文字列を返します。つまり、Mainviewcontrollerとオーディオファイル作成クラスのスコープに座っているときです。しかし、私がこのメインファイルから移動して別のNSDateクラスとして作成すると、それが呼び出されるのに問題があります。 – richg

+0

これは、今のところ、このビューコントローラ内にサービスを実行するだけです。 私の主な問題は、ファイル名の文字列(一意のファイルシーケンス番号とフォーマットされた日付で保存された)を解析し、これをテーブルで表現する必要があることです。 セルをメインタイトルと詳細テキストのサブタイトルとして表示し、 。 (どのように動作する必要があるかを示すために上の画像リンクを確認してください) もう一度、すべてのViewControllerが呼び出せるNSDateクラス/ファイルを正常に作成できれば、これでいくつかの成功を収めることさえできます。 (この投稿があまりあいまいではないことを願って) フィードバックは高く評価されています – richg

関連する問題