在我的iPhone应用程序中,视图在转换时通常会缓慢加载,就像用户单击Tab Bar Controller上的按钮一样。如果手机内存不足,则会发生这种情况。它在3GS手机上并不真正出现,但这是3G手机的一个大问题。在3G iPhone上的视图之间切换时视图加载速度缓慢 - 如何更改我的风格?
我怀疑我没有遵循创建UIViewControllers的一些最佳实践。我想我可能在init函数中做得太多了,而不是使用viewDidLoad函数或其他东西。这似乎影响了我所有的观点,所以我认为这是我的风格问题,而不是一些特定的片段。
谁能告诉我我可能会做错什么?下面是一个示例代码,来自一个UIViewController子类:
编辑:在回应这个问题:“这是被称为?
当用户点击地图上的标记这个函数被调用在这种情况下:
if(marker.label.tag == SavedBookmarkTag) {
SavedDetailScreen *savedBookmark = [[[SavedDetailScreen alloc] initBookmarkView:
[(NSDictionary *)marker.data objectForKey:@"bookmark"]]autorelease];
[savedBookmark showMap];
[self.navBar pushViewControllerWithBackBar:savedBookmark];
return;
}
编辑完
-(id)initBookmarkView: (Bookmark *)bm {
self = [self initView];
self.bookmark = bm;
primaryLabel.text = [bm title];
secondaryLabel.text = [self getLineWithLat:[bm lat] AndLon:[bm lon] AndDate:[bm timeCreated]];
return self;
}
- (id)initView {
self = [super init];
self.isWaypoint = NO;
UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"238-beveled-background.png"]];
bg.frame = CGRectMake(0, 0, 320, 376);
[self.view addSubview:bg];
bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"small-label.png"]];
[self.view addSubview:bg];
[bg release];
self.primaryLabel = [[UILabel alloc]init];
primaryLabel.font = TITLE_FONT;
primaryLabel.backgroundColor = [UIColor clearColor];
primaryLabel.textColor = LIGHT_BLUE;
self.secondaryLabel = [[UILabel alloc]init];
secondaryLabel.font = TEXT_FONT;
secondaryLabel.backgroundColor = [UIColor clearColor];
secondaryLabel.textColor = LIGHT_BLUE;
secondaryLabel.lineBreakMode = UILineBreakModeClip;
self.thirdLabel = [[UILabel alloc]init];
thirdLabel.font = TEXT_FONT;
thirdLabel.backgroundColor = [UIColor clearColor];
thirdLabel.textColor = LIGHT_BLUE;
thirdLabel.lineBreakMode = UILineBreakModeCharacterWrap;
[self.view addSubview:primaryLabel];
[self.view addSubview:secondaryLabel];
[self.view addSubview:thirdLabel];
self.loadingBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"stats-box.png"]];
loadingBackground.frame = CGRectMake(0, 115, loadingBackground.frame.size.width, loadingBackground.frame.size.height);
[self.view addSubview:loadingBackground];
[self.view sendSubviewToBack:loadingBackground];
AnimatedGif *animatedGif = [[[AnimatedGif alloc] init] autorelease];
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"35" ofType:@"gif"]];
[animatedGif decodeGIF: data];
UIImageView *loadingImage = [animatedGif getAnimation];
loadingImage.frame = CGRectMake(150,150,loadingImage.frame.size.width,loadingImage.frame.size.height);
[loadingImage startAnimating];
[loadingBackground addSubview:loadingImage];
[loadingImage release];
[self layoutSubviews];
return self;
}
- (void) layoutSubviews {
self.view.frame = CGRectMake(0,0,320,372);
primaryLabel.frame = CGRectMake(30, 30, 260, 18);
secondaryLabel.frame = CGRectMake(30 ,52, 260, 16);
thirdLabel.frame = CGRectMake(30, 72, 260, 16);
}
问题:self.view在哪里设置?在.xib中,或在其他方法?另外,什么叫initBookmarkView? – cduhn 2009-10-07 01:36:14