开发者

PathforResource issue with a .ics file, objective C

I´m just learning programming in Objective C and I got stuck with getting the information from a .ics file to appear on my tableview.

The tableview works fine. I´ve tried it with information stored directly to the NSArray. I get a detailed information view when clicking on the headers.

When i try to get the information from the .ics file I don´t even get the headers to appear. I just get a empty window.

#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.navi开发者_运维问答gationController 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


I'd guess your problem is this:

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

An iCal file (.ics) is not an xml file in property list format, which means this should return nil. You should find a different way to read iCal files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜