gpt4 book ai didi

iphone - iOS 应用程序 : Should show a specific image at a specific day, 但崩溃

转载 作者:行者123 更新时间:2023-11-29 13:03:21 25 4
gpt4 key购买 nike

我是开发 iOS 应用程序的新手,英语不是我的母语,所以请原谅我的任何错误和丑陋的代码。

我尝试创建的应用程序应该只在特定的一天显示一张特定的图像(如果日期更改,则更改图像)。因此我实现了一个检查日期的无限循环。如果它与上次更改的图像不同,则图像会再次更改。图像以“YearMonthDay.png”方案命名(例如“20131017.png”)。

我已经在 google 上搜索了很多并整理了一些代码(我知道它很丑),但每次都会崩溃。

如果有任何帮助,我将不胜感激!

smViewController.h:

#import <UIKit/UIKit.h>

@interface smViewController : UIViewController {
UIImageView* mImageView;
}

@property (nonatomic, retain) IBOutlet UIImageView* imageView;

- (IBAction)contentModeChanged:(UISegmentedControl*)segmentedControl;

@end

smViewController.m

#import "smViewController.h"

@interface smViewController ()

@end

@implementation smViewController
@synthesize imageView = mImageView;

- (void)viewDidUnload
{
self.imageView = nil;
[super viewDidUnload];
}

- (void)dealloc
{
[mImageView release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];

NSString *oldDateString = @"";

while(true)
{
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy/MM/dd"];
NSString *dateString = [dateFormat stringFromDate:today];
NSLog(@"date: %@", dateString);
if([dateString isEqualToString: oldDateString])
{
}
else
{
NSAssert(self.imageView, @"self.imageView is nil. Check your IBOutlet connections");
UIImage* image = [UIImage imageNamed:dateString];
NSAssert(image, @"image is nil. Check that you added the image to your bundle and that the filename above matches the name of you image.");
self.imageView.backgroundColor = [UIColor whiteColor];
self.imageView.clipsToBounds = YES;
self.imageView.image = image;
oldDateString = dateString;
}
[dateFormat release];
}
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

最佳答案

您应该在您的应用程序 UIApplicationDelegate 中覆盖 - (void)applicationSignificantTimeChange:(UIApplication *)application。然后您将在日期更改时收到一个事件,您可以删除任何循环或计时器。

关于iphone - iOS 应用程序 : Should show a specific image at a specific day, 但崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19255870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com