UIScrollView错误-EXC_BREAKPOINT(代码= EXC_i386_BPT,子代码= 0x0)错误

时间:2013-01-06 16:57:34

标签: ios6

我正在iOS上实现一些代码,并突然遇到如上所述的错误。我无法弄清楚问题的根源是什么。但根据我的分析,由于UIScrollView。 我正在使用ios 6进行开发。 附加错误的屏幕截图。enter image description here

以下是我用于开发的代码。

@interface TutorialDetailViewController ()

@end

@implementation TutorialDetailViewController

@synthesize managedObjectContext;
@synthesize scrollView;
@synthesize imageView;
@synthesize textView;
@synthesize imageTapGestureRecognizer;
@synthesize imagePath;
@synthesize separator;

-(void) dealloc
{
    [managedObjectContext release];
    [scrollView release];
    [imageView release];
    [textView release];
    [imageTapGestureRecognizer release];
    [imagePath release];
    [separator release];
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    NSLog(@"View Did Load - Tutorial Detail View Controller");

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    PocketScholarAppDelegate *delegateObject = (PocketScholarAppDelegate *)[[UIApplication sharedApplication] delegate];

    if(self.managedObjectContext == nil)
    {
        self.managedObjectContext = [delegateObject managedObjectContext];
    }

    //UI Customization

    UIView *backButtonView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 42, 42)] autorelease];

    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 42, 42)];
    UIImageView *separtorView = [[UIImageView alloc] initWithFrame:CGRectMake(41, 0, 1, 42)];
    separtorView.image = [UIImage imageNamed:@"NavButtonSeperator.png"];

    [backButton setBackgroundImage:[UIImage imageNamed:@"NavBackIcon.png"]
                          forState:UIControlStateNormal];
    [backButton addTarget:self
                   action:@selector(backAction)
         forControlEvents:UIControlEventTouchUpInside];

    [backButtonView addSubview:backButton];
    [backButtonView addSubview:separtorView];

    [separtorView release];
    [backButton release];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: backButtonView];

    //fetch value of the selected tutorial from the user defaults
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSInteger tutorialId = [defaults integerForKey:SELECTED_TUTORIAL];

    NSPredicate *tutorialPredicate = [NSPredicate predicateWithFormat:@"tut_id==%d",tutorialId];
    NSMutableArray *tutorialArray = [NSObject getDataFromLocalDB:TUTORIAL_ENTITY withPredicate:tutorialPredicate forObjectContext:managedObjectContext];

    Tutorials *tObj = [tutorialArray objectAtIndex:0];

    self.title = tObj.tut_name;

    NSArray *documentDirectoryArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [documentDirectoryArray lastObject];

     self.imagePath = [documentDirectory stringByAppendingPathComponent:tObj.tut_image];

    CGRect screenRect = [[UIScreen mainScreen] bounds];

    //Set the content size of the scroll view container
    self.scrollView.contentSize = CGSizeMake(screenRect.size.width, screenRect.size.height);

    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(screenRect.size.width/2-70, 20, screenRect.size.width/2-20, screenRect.size.height/2-20)];
    self.imageView.backgroundColor = [UIColor clearColor];
    self.imageView.userInteractionEnabled = YES;

    self.imageTapGestureRecognizer = [[UITapGestureRecognizer alloc]
                                                         initWithTarget:self
                                                         action:@selector(imageTapped)];
    self.imageTapGestureRecognizer.numberOfTapsRequired = 1;
    [self.imageView addGestureRecognizer:self.imageTapGestureRecognizer];

    self.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:imagePath]];

    if(![tObj.tut_description isEqualToString:@""])
    {
        self.textView = [[UITextView alloc] init];
        [self.textView sizeToFit];
        self.textView.backgroundColor = [UIColor clearColor];
        self.textView.font = [UIFont fontWithName:FONT_NAME size:14.0];
        self.textView.userInteractionEnabled = NO;
        self.textView.textColor = [UIColor colorWithRed:109.0/255.0 green:109.0/255.0 blue:109.0/255.0 alpha:1.0];
        self.textView.text = tObj.tut_description;
        self.textView.frame = CGRectMake(20,
                                         self.imageView.frame.size.height+60,
                                         screenRect.size.width-40,
                                         screenRect.size.height);
    }

    self.scrollView.showsHorizontalScrollIndicator = NO;

    self.separator = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                   self.imageView.frame.size.height+40,
                                                                   screenRect.size.width,
                                                                   3)];
    self.separator.image = [UIImage imageNamed:@"NavShadow.png"];

    [self.scrollView addSubview:self.imageView];
    [self.scrollView addSubview:separator];
    if(![tObj.tut_description isEqualToString:@""])
    {
        [self.scrollView addSubview:textView];

        CGRect textViewFrame = [textView frame];
        textViewFrame.size.height = self.textView.contentSize.height+40;
        self.textView.frame = textViewFrame;
    }

    CGFloat scrollContentHeight = screenRect.size.height + 80;
    self.scrollView.contentSize = CGSizeMake(screenRect.size.width, scrollContentHeight);

    self.view = self.scrollView;

//    [separator release];
}

- (void)didReceiveMemoryWarning
{
    NSLog(@"Did Receive Memory Warning");
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Custom Methods
-(void) backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void) imageTapped
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:imagePath forKey:SELECTED_IMAGE];
    [defaults synchronize];

    TutorialImageViewController *imageController = [[TutorialImageViewController alloc] initWithNibName:@"TutorialImageViewController" bundle:nil];
    [self.navigationController pushViewController:imageController animated:YES];
    [imageController release];

}

@end

0 个答案:

没有答案