gpt4 book ai didi

objective-c - .ics 文件的 PathforResource 问题, Objective-C

转载 作者:行者123 更新时间:2023-12-03 17:16:55 24 4
gpt4 key购买 nike

我刚刚学习 Objective C 编程,但我一直在从 .ics 文件中获取信息以显示在我的表格 View 上。

表格 View 工作正常。我已经尝试过将信息直接存储到 NSArray 中。单击标题时我会看到详细信息 View 。

当我尝试从 .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

最佳答案

我猜你的问题是这样的:

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

iCal 文件 (.ics) 不是属性列表格式的 xml 文件,这意味着它应该返回 nil。您应该找到一种不同的方式来读取 iCal 文件。

关于objective-c - .ics 文件的 PathforResource 问题, Objective-C ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4075779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com