2010-11-02 43 views
1

我剛剛在Objective C中學習編程,而且我從一個.ics文件中獲取信息出現在我的tableview中。PathforResource與一個.ics文件問題,目標C

該tableview工作正常。我試過將信息直接存儲到NSArray中。點擊標題時,我會看到詳細的信息視圖。

當我試圖從.ics文件中獲取信息時,我甚至不會顯示標題。我只是得到一個空的窗口。

#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

克里斯,你的大部分代碼與你的問題無關,甚至評論,它是很難通過閱讀找到有問題的地方。花點時間讓你的問題可讀,這樣你可以更快地得到答案。 – Vladimir 2010-11-02 14:48:31

回答

1

我猜你的問題是這樣的:

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

iCal文件(的.ics)是不是在屬性列表格式,這意味着本應返回nil的XML文件。你應該找到一種不同的方式來閱讀iCal文件。

+0

好嗎?怎麼樣?我不知道如何解決這個問題......我嘗試了谷歌的方式,但似乎沒有人做過這個... – Chris79 2010-11-02 15:48:43

+0

我想找到如何創建ics文件也但沒有看到如何去做,你有沒有什麼運氣? – BDGapps 2011-06-02 21:11:49