Angesichts der Multitasking von iOS Ich dachte, es wäre nicht ein Schmerz zu pausieren und meine App, durch Drücken der Home-Taste oder aufgrund eines Anrufs, aber für einen bestimmten View-Controller abstürzen .UI View Controller stürzt nach Unterbrechung ab
Die Navigationsleiste funktioniert gut also, wenn ich tippen Sie auf „Zurück“, es ist in Ordnung, aber wenn ich versuche, Kontrollen des angezeigten UI-View-Controller tippen dann bekomme ich EXC_BAD_ACCESS .. =/
finden Sie den Code mein problematischer View Controller unten. Ich bin mir selbst nicht sicher, weil ich loadView benutzt habe, um seine View zu erstellen. Abgesehen von diesem Unterbrechungsproblem funktioniert es jedoch einwandfrei.
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
Irgendwelche Vorschläge?
Danke,
F.
lol! Jer danke für die sofortige Antwort. Ich habe meinen Code in meiner Frage veröffentlicht; auch der Absturzbericht ist die Nachricht in der Konsole? Abgesehen von Programm empfangen Signal EXC BAD ACCESS und "Kann nicht lesen Symbole .." gibt es nichts anderes .. Danke! F. – nosuic
Wenn Sie auf dem Gerät laufen, gehen Sie zum Organizer, klicken Sie auf Ihr Gerät und dann auf Geräteprotokolle. Finden Sie die Anwendung/Datum Combo, wenn Sie den Absturz hatten (oder reproduzieren Sie es und notieren Sie sich die Zeit). Der Stack-Trace dort im entsprechenden Thread, der abgestürzt ist, ist wichtig. – jer