我的应用程序运行良好,几分钟后,在编辑了应用程序的另一部分后,它开始从我什至没有处理的视图控制器中抛出 EXC_BAD_ACCESS 错误。我认为可能影响它的唯一一件事是,我编辑->折射->转换为 Obj-C ARC...我也只为指定的文件做了它,而不是我的整个项目令人困惑。当我相信错误开始发生时,我正在关注本教程...... http://sonnyparlin.com/2011/12/pulltorefresh-ios-5-and-arc-tutorial/ 此外,应用程序启动正常,它只是在崩溃时崩溃在表格视图中单击了一个单元格。任何帮助将不胜感激!
此行发生错误:
self.releaselink = [[sortedArray objectAtIndex:indexPath.row] objectForKey:@"link"];
这是我的错误源自的代码:
@implementation PressReleaseViewController
@synthesize releaselink;
UILabel *departmentNamesLabel;
CGRect *departmentNamesFrame;
- (void)viewDidLoad {
// Load path to plist and sort based on "name"
NSString *path = [[NSBundle mainBundle] pathForResource:
@"departments" ofType:@"plist"];
array = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
sortedArray = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
}
// How many sections are in the table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Set how many rows of cells are in the table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [sortedArray count];
}
// Set up table view and format for cells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
// Set text for each cell
cell.textLabel.text = [[sortedArray objectAtIndex:indexPath.row] objectForKey:@"name"];
return cell;
}
// Set how tall each cell is
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
// Set push to new view controller
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.releaselink = [[sortedArray objectAtIndex:indexPath.row] objectForKey:@"link"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
MainViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"main"];
[vc setReleaseLink:self.releaselink];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)viewDidUnload {
pressReleases = nil;
[super viewDidUnload];
}
@end
头文件”
@interface PressReleaseViewController : UITableViewController {
IBOutlet UITableView *pressReleases;
NSArray *array;
NSArray *sortedArray;
NSString *releaselink;
}
@property (nonatomic, retain) NSString *releaselink;
@end