我是开发 iOS 应用程序的新手,英语不是我的母语,所以请原谅任何错误和我丑陋的代码。
我正在尝试创建的应用程序应该只在特定的一天显示一张特定的图像(如果日期发生变化,请更改图像)。因此,我实现了一个无限循环,在其中检查日期。如果它与上次更改的图像不同,则图像再次更改。图像以“YearMonthDay.png”-方案命名(例如“20131017.png”)。
我已经用谷歌搜索了很多代码(我知道这很丑),但每次都会崩溃。
我真的很感激任何帮助!
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