尝试访问“MySkinsView”时出现以下错误
2013-07-06 14:57:28.523 Skin Creator[778:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (1) beyond bounds (0)'
*** First throw call stack:
(0x335662a3 0x3b1d997f 0x335661c5 0x334dec01 0x77741 0x353b954d 0x3539e313 0x353b57cf 0x35371803 0x3511bd8b 0x3511b929 0x3511c85d 0x3511c243 0x3511c051 0x3511beb1 0x3353b6cd 0x335399c1 0x33539d17 0x334acebd 0x334acd49 0x3705d2eb 0x353c2301 0x6b171 0x6b0f8)
libc++abi.dylib: terminate called throwing an exception
我的 .m 如下:
#import "MySkinsView.h"
#import <QuartzCore/QuartzCore.h>
#import "CreateASkinView.h"
#import "SkinManipulator.h"
@interface MySkinsView ()
@end
@implementation MySkinsView{
int deletedIndexPath;
}
@synthesize customCell, cellImage, cellLabel, array, alertView, TableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *arrayFileName = [documentsDirectory stringByAppendingPathComponent:@"example.dat"];
NSString *errString;
NSData *serialized = [NSData dataWithContentsOfFile:arrayFileName];
array =
[NSPropertyListSerialization propertyListFromData:serialized
mutabilityOption:NSPropertyListMutableContainers
format:NULL
errorDescription:&errString];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)viewDidAppear:(BOOL)animated{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *arrayFileName = [documentsDirectory stringByAppendingPathComponent:@"example.dat"];
NSString *errString;
NSData *serialized = [NSData dataWithContentsOfFile:arrayFileName];
array =
[NSPropertyListSerialization propertyListFromData:serialized
mutabilityOption:NSPropertyListMutableContainers
format:NULL
errorDescription:&errString];
if (errString)
{
NSLog(@"%@", errString);
}
[super viewDidLoad];
[TableView reloadData];
}
-(int)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [array count];
}
-(UITableViewCell* )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"cell identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = customCell;
self.customCell = nil;
}
NSArray *skinInfo=[array objectAtIndex:indexPath.row];
cellLabel.text=[skinInfo objectAtIndex:1];
cellLabel.font=[UIFont fontWithName:@"CurseCasualRegular" size:17];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tableviewbg.png"]];
UIImage *skin=[UIImage imageWithData:[skinInfo objectAtIndex:0]];
UIImage *frontView=[[SkinManipulator alloc]createFrontViewOfSkin:skin];
cellImage.image=frontView;
cellImage.layer.magnificationFilter=kCAFilterNearest;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *skinInfo=[array objectAtIndex:indexPath.row];
CreateASkinView *createASkin;
createASkin = [[CreateASkinView alloc] initWithNibName:@"CreateASkinView" bundle:nil];
createASkin.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
createASkin.indexPathOfSkin=indexPath.row+1;
createASkin.skin=[UIImage imageWithData:[skinInfo objectAtIndex:0]];
createASkin.skinName=[skinInfo objectAtIndex:1];
[self presentViewController:createASkin animated:YES completion:nil];
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
alertView=[[UIAlertView alloc]initWithTitle:@"Are you sure you want to delete this skin?" message:nil delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
deletedIndexPath=indexPath.row;
[alertView show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0){
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *arrayFileName = [documentsDirectory stringByAppendingPathComponent:@"example.dat"];
[array removeObjectAtIndex:deletedIndexPath];
NSString *errString;
NSData *serialized =
[NSPropertyListSerialization dataFromPropertyList:array
format:NSPropertyListBinaryFormat_v1_0
errorDescription:&errString];
[serialized writeToFile:arrayFileName atomically:YES];
[TableView reloadData];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)back:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
当我点击打开我的皮肤的按钮时会发生这种情况。请告知您是否可以找到错误。