2010-12-31 6 views
0

iOSのマルチタスクを考えると、ホームボタンを押すか、電話をかけてアプリを一時停止して再開するのは苦痛ではないと思ったが、特定のView Controller 。私は、「戻る」、それは大丈夫だが、私は表示されたUIビューコントローラのコントロールをタップしようとした場合、私はEXC_BAD_ACCESSを取得します。.. =/中断後にUI View Controllerがクラッシュする

をタップすると

ナビゲーションバーが細かいすなわち働いているのコードを見つけてください。下の私の問題のView Controller。ロードビューを使用してそのビューを構築しているため、私自身はあまりよく分かりません。しかし、この中断問題とは別に、正常に動作します。

StoreViewController.h

#import <UIKit/UIKit.h> 

@protocol StoreViewDelegate <NSObject> 
@optional 
- (void)DirectionsClicked:(double)lat:(double)lon; 
@end 

@interface StoreViewController : UIViewController 
{ 
    double latitude; 
    double longitude; 
    NSString *description; 
    NSString *imageURL; 
    short rating; 
    NSString *storeType; 
    NSString *offerType; 

    UIImageView *imageView; 
    UILabel *descriptionLabel; 

    id<StoreViewDelegate> storeViewDel; 
} 

@property (nonatomic) double latitude; 
@property (nonatomic) double longitude; 
@property (nonatomic) short rating; 
@property (nonatomic,retain) NSString *description; 
@property (nonatomic,retain) NSString *imageURL; 
@property (nonatomic,retain) NSString *storeType; 
@property (nonatomic,retain) NSString *offerType; 
@property (assign) id<StoreViewDelegate> storeViewDel; 

@end 

StoreViewController.m

#import "StoreViewController.h" 
#import <QuartzCore/QuartzCore.h> 

@interface StoreViewController() 

-(CGSize) calcLabelSize:(NSString *)string withFont:(UIFont *)font maxSize:(CGSize)maxSize; 

@end 

@implementation StoreViewController 

@synthesize storeViewDel, longitude, latitude, description, imageURL, rating, offerType, storeType; 

- (void)mapsButtonClicked:(id)sender 
{ 
} 

- (void)loadView 
{ 
    UIView *storeView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)]; 

    // Colours 
    UIColor *lightBlue = [[UIColor alloc] initWithRed:(189.0f/255.0f) 
               green:(230.0f/255.0f) 
               blue:(252.0f/255.0f) alpha:1.0f]; 

    UIColor *darkBlue = [[UIColor alloc] initWithRed:(28.0f/255.0f) 
               green:(157.0f/255.0f) 
               blue:(215.0f/255.0f) 
               alpha:1.0f]; 

    // Layout 
    int width = self.navigationController.view.frame.size.width; 
    int height = self.navigationController.view.frame.size.height; 
    float firstRowHeight = 100.0f; 
    int margin = width/20; 
    int imgWidth = (width - 3 * margin)/2; 

    // Set ImageView 
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(margin, margin, imgWidth, imgWidth)]; 
    CALayer *imgLayer = [imageView layer]; 
    [imgLayer setMasksToBounds:YES]; 
    [imgLayer setCornerRadius:10.0f]; 
    [imgLayer setBorderWidth:4.0f]; 
    [imgLayer setBorderColor:[lightBlue CGColor]]; 
    // Load default image 
    NSData *imageData = [NSData dataWithContentsOfFile:@"thumb-null.png"]; 
    UIImage *image = [UIImage imageWithData:imageData]; 
    [imageView setImage:image]; 

    [storeView addSubview:imageView]; 

    // Set Rating 
    UIImageView *ratingView = [[UIImageView alloc] initWithFrame:CGRectMake(3 * width/4 - 59.0f, 
                     margin, 
                     118.0f, 
                     36.0f)]; 
    UIImage *ratingImage = [UIImage imageNamed:@"bb-rating-0.png"]; 
    [ratingView setImage:ratingImage]; 
    [ratingImage release]; 

    [storeView addSubview:ratingView]; 

    // Set Get Directions button 
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(3 * width/4 - 71.5f, 
                   36.0f + 2*margin, 
                   143.0f, 63.0f)]; 
    [btn addTarget:self action:@selector(mapsButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    UIImage *mapsImgUp = [UIImage imageNamed:@"bb-maps-up.png"]; 
    [btn setImage:mapsImgUp forState:UIControlStateNormal]; 
    [mapsImgUp release]; 
    UIImage *mapsImgDown = [UIImage imageNamed:@"bb-maps-down.png"]; 
    [btn setImage:mapsImgDown forState:UIControlStateHighlighted]; 
    [mapsImgDown release]; 

    [storeView addSubview:btn]; 
    [btn release]; 

    // Set Description Text 
    UIScrollView *descriptionView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 
                        imgWidth + 2 * margin, 
                        width, 
                        height - firstRowHeight)]; 
    descriptionView.backgroundColor = lightBlue; 
    CGSize s = [self calcLabelSize:description withFont:[UIFont systemFontOfSize:18.0f] maxSize:CGSizeMake(width, 9999.0f)]; 
    descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(margin, margin, width - 2 * margin, s.height)]; 
    descriptionLabel.lineBreakMode = UILineBreakModeWordWrap; 
    descriptionLabel.numberOfLines = 0; 
    descriptionLabel.font = [UIFont systemFontOfSize:18.0f]; 
    descriptionLabel.textColor = darkBlue; 
    descriptionLabel.text = description; 
    descriptionLabel.backgroundColor = lightBlue; 

    [descriptionView addSubview:descriptionLabel]; 
    [storeView addSubview:descriptionView]; 
    [descriptionLabel release]; 

    [lightBlue release]; 
    [darkBlue release]; 

    self.view = storeView; 
    [storeView release]; 
} 

- (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. 
} 

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

- (void)dealloc 
{ 
[imageView release]; 
    [descriptionLabel release]; 

    [super dealloc]; 
} 

@end 

任意の提案ですか?

はF.

答えて

0

問題は、割り当てられていないUIImageをリリースしたことです。

[ratingImage release]; 
[mapsImgUp release]; 
[mapsImgDown release]; 

F.

1

はおそらく、あなたのクラッシュレポートを見て、それがクラッシュのWHEREのアイデアを得る、そしてそれはあなたのものに明確ではない場合、私たちは、関連するコードを掲載することにより、あなたを助けて助けて、

をありがとうクラッシュを引き起こしています。私たちはさらにあなたを手伝うことができるかもしれませんが、必要な作業を最初に行う必要があります。手元の適切な情報を使って自分で解決するようにしてください。あなたは何を探すべきかを知っているので、どうぞ、行き、ユニコーンに行ってください!

+0

笑:次の行を消去すると、私の問題を解決しました! Jerはすぐに対応してくれてありがとう。私は自分のコードを私の質問に掲載しました。クラッシュレポートもコンソールのメッセージですか?プログラム受信信号EXC BAD ACCESSと 'Unsable to be symbols ..'以外には何もありません。ありがとう! F. – nosuic

+1

デバイスで実行している場合は、オーガナイザでデバイスをクリックし、デバイスログをタップします。クラッシュしたときにアプリケーション/日付のコンボを見つけます(またはそれを再現して時間を記録します)。クラッシュした適切なスレッド内のスタックトレースが重要です。 – jer

関連する問題