第二次触摸后UIButton EXC_BAD_ACCESS?

时间:2012-02-23 14:54:48

标签: ios uibutton exc-bad-access

每当我第二次使用“Touch Up Inside”触摸UIButton时,应用程序第二次崩溃EXC_BAD_ACCESS。我找不到问题,认为一切都很好。

这是我的.h文件:

#import <UIKit/UIKit.h>

@interface AnleitungWebViewController : UIViewController {

    UIWebView *anleitungwebview;
    NSURL *pdfpfad_anleitung;
    NSString *aktuellesBild;
    NSString *nummer;
    IBOutlet UIActivityIndicatorView *indicator;
    IBOutlet UILabel *laden;
    IBOutlet UIButton *vor;
}

@property (nonatomic, retain) IBOutlet UIWebView *anleitungwebview;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *indicator;
@property (nonatomic, retain) IBOutlet UILabel *laden;
@property (nonatomic, retain) IBOutlet UIButton *vor;
@property (nonatomic, retain) NSURL *pdfpfad_anleitung;
@property (nonatomic, retain) NSString *aktuellesBild;
@property (nonatomic, retain) NSString *nummer;

- (IBAction)zuruck:(id)sender;
- (IBAction)vor:(id)sender;


@end

我的.m文件:

#import "AnleitungWebViewController.h"

@implementation AnleitungWebViewController

@synthesize anleitungwebview, pdfpfad_anleitung, indicator, laden, aktuellesBild, nummer, vor;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //NSURLRequest *request = [[NSURLRequest alloc] initWithURL:pdfpfad_anleitung];
    //[anleitungwebview loadRequest:request];

    //aktuellesBild = @"anl_30148_120701-de-001";

    NSString *path = [[NSBundle mainBundle] pathForResource:aktuellesBild ofType:@"jpg"];
    NSURL *url = [NSURL URLWithString:path];

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    [anleitungwebview loadRequest:request];
}

- (void)webViewDidStartLoad:(UIWebView *) webView {

    [indicator startAnimating];
    indicator.hidden = NO;
    laden.hidden = NO;

}

- (void)webViewDidFinishLoad:(UIWebView *) webView {

    [indicator stopAnimating];
    indicator.hidden = YES;
    laden.hidden = YES;

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)zuruck:(id)sender {

    nummer = [aktuellesBild substringFromIndex:[aktuellesBild length]-3];

    int num = [nummer intValue];
    num = num - 1;

    if (num < 10) {
        nummer = @"00";
        nummer = [nummer stringByAppendingString:[NSString stringWithFormat:@"%d", num]];
    }
    else if (num > 9) {
        nummer = @"0";
        nummer = [nummer stringByAppendingString:[NSString stringWithFormat:@"%d", num]];
    }
    else{
        nummer = [nummer stringByAppendingString:[NSString stringWithFormat:@"%d", num]];
    }

    aktuellesBild = [aktuellesBild substringToIndex:[aktuellesBild length]-3];
    aktuellesBild = [aktuellesBild stringByAppendingString:nummer];

    NSString *path = [[NSBundle mainBundle] pathForResource:aktuellesBild ofType:@"jpg"];
    NSURL *url = [NSURL URLWithString:path];

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    [anleitungwebview loadRequest:request];

    NSLog(@"%@", aktuellesBild);
}

- (IBAction)vor:(id)sender {

    NSLog(@"TEST");

    nummer = [aktuellesBild substringFromIndex:[aktuellesBild length]-3];

    int num = [nummer intValue];
    num = num + 1;

    if (num < 10) {
        nummer = @"00";
        nummer = [nummer stringByAppendingString:[NSString stringWithFormat:@"%d", num]];
    }
    else if (num > 9) {
        nummer = @"0";
        nummer = [nummer stringByAppendingString:[NSString stringWithFormat:@"%d", num]];
    }
    else{
        nummer = [nummer stringByAppendingString:[NSString stringWithFormat:@"%d", num]];
    }

    aktuellesBild = [aktuellesBild substringToIndex:[aktuellesBild length]-3];
    aktuellesBild = [aktuellesBild stringByAppendingString:nummer];

    NSString *path = [[NSBundle mainBundle] pathForResource:aktuellesBild ofType:@"jpg"];
    NSURL *url = [NSURL URLWithString:path];

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    [anleitungwebview loadRequest:request];

    NSLog(@"%@", aktuellesBild);
}

- (void)dealloc {

    [anleitungwebview release];
    [laden release];
    [indicator release];
    [pdfpfad_anleitung release];
    [aktuellesBild release];
    [nummer release];
    [vor release];
    [super dealloc];
}


@end

有想法的人吗?

1 个答案:

答案 0 :(得分:0)

您不检查字符串长度

nummer = [aktuellesBild substringFromIndex:[aktuellesBild length]-3];