【发布时间】:2011-07-06 06:08:13
【问题描述】:
我有一个在应用程序加载时加载的 MenuViewController;它是 UINavigationController 的根视图。
在视图中,我有一个 UIButton,其中包含一个从 URL 加载的图像,以及一个标签(它是一张指示天气和当前温度的图片)。
一切正常,但如果我在 iPhone 4 上使用多任务应用程序,当按下主页按钮然后重新打开应用程序时,我需要 UIButton 图像和 temp。要重新加载的标签。
我尝试在我的 AppDelegate 中的 applicationDidBecomeActive 下调用它:
[self parseWeatherXML]; //re-parse weather data
[menuViewController reloadWeatherData]; //loads the image/label from the XML
没有运气。
我还尝试在 applicationWillResign 中释放 menuViewController,然后在 applicationDidBecomeActive 中重新分配 menuViewController,以便再次调用 viewDidLoad 方法,这两种方式最终都会导致我的应用程序崩溃。
任何帮助表示赞赏!
编辑 这是我通过通知调用的方法:
- (void)reloadWeather
{
[self parseWeatherXML];
UIImage *img = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:iconURL]]];
if (img != nil)
{
NSLog(@"setting image");
[weatherButton setImage:img forState:normal];
img = nil;
}
currentTemp = [currentTemp stringByAppendingString:@"°F"];
[tempLabel setText:currentTemp];
tempLabel.adjustsFontSizeToFitWidth = YES;
if([self isIPad])
{
tempLabel.textAlignment = UITextAlignmentRight;
[tempLabel setFont: [UIFont systemFontOfSize: 45.0]];
}
currentTemp = nil;
}
【问题讨论】:
-
你能把控制台消息粘贴到这里吗?
-
@robin 我得到了 EXE_BAD_ACCESS。加载时我不正确,但是在我按下主页并重新启动应用程序几次之后。出于某种原因,标签在应该显示温度时显示 MenuViewController。
-
在此处粘贴控制台输出。
标签: iphone ios uibutton reload multitasking