1

I am Working on Recording Application.in This Application i Save my Recording with my own Text and it also Save the Recording with Current Date and Time.As my below Code show

-(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];
}

Now After Saving Recording When i goes to SaveRecording Class Where actually i Show all these Recording in Tableview.here my Code is

- (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];
 }

And After That i Assign "directoryContent" Which is my NSMutablArray To 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;
}

And Finaly my UITableView is Look like this Below ScreenShot enter image description here

My All this Brief discussion purpose is that as my Screen shot show That UITableview Cell Show my Text and Current date and Time.Now i want to Split this directoryContent Array data into Two prats.The part which Consist of Current date and time i want to Assign it capitalLabel which is redpart of Cell in UITableview And Text to stateLabel Which is Below part of Cell in UITableview.Any help will be Appriated.Thanks in Advance.

3
  • Why dont you try this.................. 1) You can create an array of dictionary and save them separately or 2) While creating that string dont just append use appendWithFormat and add a special character between the two like @"+%@",mySongName and while displaying you can use componentsSeparatedByString@"+" on it and it will return you an Array of two string
    – superGokuN
    Dec 6, 2012 at 8:20
  • sorry that's not appendWithFormat it's appendFormat :)
    – superGokuN
    Dec 6, 2012 at 8:28
  • naveen post answer please still confusion in my mind.
    – NSCool
    Dec 6, 2012 at 9:05

2 Answers 2

1

First you need to append your string like this

NSString *file3 = [file stringByAppendingString:@"+"];


NSString *fina= [file3 stringByAppendingString:mySongname];

after that you need to seperate it like

NSArray *Array = [str componentsSeparatedByString:@"+"]; 
NSLog(@"myindex0str:%@",[Array objectAtIndex:0]); 
NSLog(@"myindex1str:%@",[Array objectAtIndex:1]);

so you will get the both time and songname individually.

0
1

Hi Lena you can try the following things

1) Array of Dictionary

Save your Date and Song name separately in a Dictionary

 NSDictionary *myData    =   [NSDictionary dictionaryWithObjectsAndKeys:myDateObj,@"SongDate",mySongName,@"SongName", nil];

[myMutableArray addObject:myData]//myMutableArray is a NSMutableArray;

Now you can use it as follows

NSDictionary *dict = [directoryContent objectAtIndex:indexPath.row];
stateLabel.text =    [dict objectForKey:@"SongName"];
capitalLabel.text =  [dict objectForKey:@"SongDate"];

OR

2) Your can do a little trick :)

NSString *fina=[file stringByAppendingFormat:@"+%@",mySongname];

NSArray *Array  =   [fina componentsSeparatedByString:@"+"];

capitalLabel.text =  [Array objectAtIndex:0];

stateLabel.text =    [Array objectAtIndex:1];

Here while appending you can use format and add any special character which you can use later to split the string.

Hope this will help you in any ways :)

5
  • Thanks for your help but still it not works for me beacuse if you look my code i save all these things in Document Directory and then Fetching all these thing in another Class in directoryContent mutablearry to show it in UITableview.So please here till me any trik when i fectching data from Document dirctory in directoryContent Mutablearry .how to split it.Thanks
    – NSCool
    Dec 6, 2012 at 9:39
  • This line Creates problem for me when i used you above method soundFilePath = [soundFilePath stringByAppendingPathComponent:myMutableArray];
    – NSCool
    Dec 6, 2012 at 9:52
  • @lena at you just want to split the Date and Name of the songs? There must be somewhere in your code you are saving them inside a string, If I am not wrong here NSString *fina=[file stringByAppendingString:mySongname]; your are doing this, if this is the case then use the second method it will surely going to work for you.
    – superGokuN
    Dec 6, 2012 at 11:37
  • When i used your second method here is the result NSString *fina=[file stringByAppendingFormat:@"+",mySongname]; then fetching this way NSString *str=[directoryContent objectAtIndex:indexPath.row]; NSLog(@"myindexstr:%@",str); NSArray *Array = [str componentsSeparatedByString:@"+"]; NSLog(@"myindex0str:%@",[Array objectAtIndex:0]); NSLog(@"myindex1str:%@",[Array objectAtIndex:1]); and my nslog result is myindexstr:06:Dec:12_04:29:16 PM+ myindex0str:06:Dec:12_04:29:16 PM myindex1str: index 1 is empty
    – NSCool
    Dec 6, 2012 at 11:41
  • @lena NSString *fina=[file stringByAppendingFormat:@"+",mySongname]; sorry my mistake Forgot to use the format specifier :(, Edited my answer it should be NSString *fina=[file stringByAppendingFormat:@"+%@",mySongname];
    – superGokuN
    Dec 7, 2012 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.