我正在录制应用程序。在这个应用程序中,我用我自己的文本保存我的录音,它还用当前日期和时间保存录音。如下面的代码所示
-(IBAction)RecButtonPress:(id)sender
{
NSLog(@"Song name:%@",mySongname);
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44000.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[recordSetting setValue: [NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
NSDate* now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd:MMM:YY_hh:mm:ss a"];
NSString *file= [dateFormatter stringFromDate:now];
NSString *fina=[file stringByAppendingString: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];
NSLog(@"Uf:%@",recordedTmpFile);
recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
[recordSetting release];
[dateFormatter release];
}
现在保存记录后,当我转到 SaveRecording 类时,实际上我在 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]);
NSLog(@"arraydata: %@", directoryContent );
[directoryContent retain];
[self.tableView reloadData];
}
之后,我将我的 NSMutablArray 的“directoryContent”分配给 UITableview。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [directoryContent count];
}
///////////////////////////////////////// ////////////////////////////////////
- (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, 120, 20)];
//capitalLabel.text=@"mydata";
capitalLabel.backgroundColor=[UIColor redColor];
capitalLabel.tag = CapitalTag;
[capitalLabel setFont:[UIFont systemFontOfSize:9]];
[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 = [datesaving objectAtIndex:indexPath.row];
return cell;
}
最后我的 UITableView 在屏幕截图下面看起来像这样
我所有这些简短讨论的目的是,当我的屏幕截图显示 UITableview 单元格显示我的文本和当前日期和时间。现在我想将此目录内容数组数据拆分为两个 prats。我想要的包含当前日期和时间的部分将它分配给 UITableview 中单元格的红色部分的大写标签,并将文本分配给位于 UITableview 中单元格部分下方的 stateLabel。任何帮助都将得到应用。提前致谢。