2010-11-02 5 views
1

Je suis en train d'apprendre la programmation en Objective C et je me suis retrouvé coincé avec l'obtention de l'information d'un fichier .ics sur ma tableview.Problème PathforResource avec un fichier .ics, objectif C

La vue de la table fonctionne bien. Je l'ai essayé avec des informations stockées directement dans NSArray. Je reçois une vue détaillée des informations en cliquant sur les en-têtes. Lorsque j'essaie d'obtenir les informations du fichier .ics, les en-têtes n'apparaissent même pas. Je viens d'avoir une fenêtre vide.

#import "RootViewController.h" 
#import "DetailedInformationView.h" 


@implementation RootViewController 

@synthesize dataArray; 
@synthesize ical; 

#pragma mark - 
#pragma mark View lifecycle 

-(id)init{ 

if (self = [super init]) { 


    dataArray = [[NSMutableArray alloc]init]; 

    NSString *path = [[NSBundle mainBundle] pathForResource:@"timeedit" ofType:@"ics"]; 
    NSDictionary *dict = [NSDictionary dictionaryWithObject: path forKey:@"Calendar app"]; 

    [dataArray addObject:dict]; 

    NSLog(@"init"); 

    self.navigationItem.title = @"Calendar App"; 

} 

return self; 
} 

-(NSMutableArray*)parseCalendarWithString:(NSString*)_file{ 

//NSMutableArray *parse = [[NSMutableArray alloc] initWithCapacity:[self count]]; 

} 

-(NSMutableArray*)parseCalendarWithPath:(NSString*)_path{ 

//NSString *path = [[NSBundle mainBundle] pathForResource:@"timeedit" ofType:@"ics"]; 

//NSDictionary *dict = [[NSDictionary alloc] initWithPath: path]; 


//self.dataArray = [NSArray: dict ]; 



//[dict release]; 

//return ; 
} 

-(void)sortArray:(NSMutableArray*)_array by:(iCalSortBy)_by{ 

//dataArray = [[NSMutableArray alloc]init]; 
//NSMutableArray *array = [[dataArray alloc]sortedArrayUsingSelector::@selector(compare:)]; 

//self.dataArray = array; 

} 

- (void)viewDidLoad { 

[self init]; 

//self.dataArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil]; 

//ical = [[iCalParser alloc] initWithPath:@"timeedit"]; 

//self.dataArray = [NSMutableArray arrayWithContentsOfFile:path]; 

//NSString *path = [[NSBundle mainBundle] pathForResource:@"timeedit" ofType:@"ics"]; 
//NSDictionary *dict = [[NSDictionary alloc] initWithPath: path]; 
//self.dataArray = [NSArray arrayWithObjects:dict, nil]; 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem; 

[super viewDidLoad]; 
} 


/* 
- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
} 
*/ 
/* 
- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
} 
*/ 
/* 
- (void)viewWillDisappear:(BOOL)animated { 
[super viewWillDisappear:animated]; 
} 
*/ 
/* 
- (void)viewDidDisappear:(BOOL)animated { 
[super viewDidDisappear:animated]; 
} 
*/ 

/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations. 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 


#pragma mark - 
#pragma mark Table view data source 

// Customize the number of sections in the table view. 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 

if(section == 0){ 
    return @"Monday"; 
} 
else if (section == 1){ 
    return @"Tuesday"; 
} 
else if (section == 2){ 
    return @"Wednesday"; 
} 
else if (section == 3){ 
    return @"Thursday"; 
} 
else if (section == 4){ 
    return @"Friday"; 
} 
else if (section == 5){ 
    return @"Saturday"; 
} 
else if (section == 6){ 
    return @"Sunday"; 
} 
} 

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
NSDictionary *dict = [dataArray objectAtIndex:section]; 
NSArray *data = [dict objectForKey:@"Calendar App"]; 
    return [data count]; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

// Configure the cell. 
NSDictionary *dict = [dataArray objectAtIndex:indexPath.section]; 
NSArray *data = [dict objectForKey:@"Calendar App"]; 
NSString *cellValue = [data objectAtIndex:indexPath.row]; 
cell.textLabel.text = cellValue; 

NSLog(@"Conf Cell"); 

//cell.textLabel.text = [NSString stringWithFormat:@"%@", [dataArray objectAtIndex: indexPath.row]]; 
//cell.textLabel.text = [[ical libraryItemAtIndex:indexPath.row] valueForKey:@"DTSTART"]; 


    return cell; 
} 


/* 
// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 
*/ 


/* 
// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source. 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
    } 
} 
*/ 


/* 
// Override to support rearranging the table view. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { 
} 
*/ 


/* 
// Override to support conditional rearranging of the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Return NO if you do not want the item to be re-orderable. 
    return YES; 
} 
*/ 


#pragma mark - 
#pragma mark Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

NSDictionary *dict = [dataArray objectAtIndex:indexPath.section]; 
NSArray *data = [dict objectForKey:@"Countries"]; 
NSString *selectedrow = [data objectAtIndex:indexPath.row]; 

    DetailedInformationView *detailView = [[DetailedInformationView alloc] initWithNibName:@"DetailedInformationView" bundle:nil]; 
detailView.selectedrow = selectedrow; 
    // ... 
    // Pass the selected object to the new view controller. 
    [self.navigationController pushViewController:detailView animated:YES]; 
    [[detailView label] setText:[NSString stringWithFormat:@"%@", [dataArray objectAtIndex:indexPath.row]]]; 
    [detailView release]; 
detailView = nil; 

} 


#pragma mark - 
#pragma mark Memory management 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Relinquish ownership any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. 
    // For example: self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
[dataArray release]; 
} 


@end 
+1

Chris, la plupart de votre code n'est pas pertinent à votre problème ou même commenté, il est trop difficile de le lire pour trouver l'endroit problématique. Efforcez-vous de rendre votre question lisible afin d'obtenir une réponse beaucoup plus rapidement. – Vladimir

Répondre

1

Je suppose que votre problème est le suivant:

NSString *path = [[NSBundle mainBundle] pathForResource:@"timeedit" ofType:@"ics"]; 
NSDictionary *dict = [NSDictionary dictionaryWithObject: path forKey:@"Calendar app"]; 

Un fichier iCal (.ics) n'est pas un fichier xml sous forme de liste de biens, ce qui signifie que cela devrait revenir nil. Vous devriez trouver une façon différente de lire les fichiers iCal.

+0

ok? Comment? Je n'ai aucune idée comment résoudre ceci ... ... j'ai essayé de google pour un chemin mais il ne semble pas que quelqu'un ait fait ceci ... – Chris79

+0

J'essaye de trouver comment créer le dossier de ics aussi mais ne vois pas comment le faire avez-vous de la chance ??? – BDGapps

Questions connexes