在这里,我试图计算两个日期之间的小时数.当我运行应用程序时,它崩溃了.你能告诉我这段代码中的错误吗?
NSString *lastViewedString = @"2012-04-25 06:13:21 +0000";
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss zzz"];
NSDate *lastViewed = [[dateFormatter dateFromString:lastViewedString] retain];
NSDate *now = [NSDate date];
NSLog(@"lastViewed: %@", lastViewed); //2012-04-25 06:13:21 +0000
NSLog(@"now: %@", now); //2012-04-25 07:00:30 +0000
NSTimeInterval distanceBetweenDates = [now timeIntervalSinceDate:lastViewed];
double secondsInAnHour = 3600;
NSInteger hoursBetweenDates = distanceBetweenDates / secondsInAnHour;
NSLog(@"hoursBetweenDates: %@", hoursBetweenDates);
Run Code Online (Sandbox Code Playgroud) 我正在开发一个带有核心图表的iPhone应用程序.在一些教程的帮助下,我设法通过单点触摸和拖动来完成.如何通过多次触摸和拖动来实现?有人请帮帮我吗?

ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
EskPlotTheme *defaultTheme = [[EskPlotTheme alloc] init];
linePlot = [[EskLinePlot alloc] init];
linePlot.delegate = self;
[linePlot renderInLayer:lineHostingView withTheme:defaultTheme];
[defaultTheme release];
}
Run Code Online (Sandbox Code Playgroud)
EskLinePlot.m
- (id)init
{
self = [super init];
if (self)
{
// setting up the sample data here.
sampleData = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:6000],
[NSNumber numberWithInt:3000],
[NSNumber numberWithInt:2000],
[NSNumber numberWithInt:5000],
[NSNumber numberWithInt:7000],
[NSNumber numberWithInt:8500],
[NSNumber numberWithInt:6500], nil];
}
return self;
}
- (void)renderInLayer:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme *)theme
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; …Run Code Online (Sandbox Code Playgroud) 对于我的新项目.我已将我的csv文件内容加载为NSString.首先,我需要通过换行拆分它,然后用逗号分隔每一行.我怎么能循环这一切?请你帮助我好吗?
CSV内容
"^ GSPC",1403.36,"4/27/2012","4:32 pm",+ 3.38,1400.19,1406.64,1397.31,574422720"^ IXIC",3069.20,"4/27/2012","5:30 pm " + 18.59,3060.34,3076.44,3043.30,0
ViewController.m
NSString* pathToFile = [[NSBundle mainBundle] pathForResource: @"quotes" ofType: @"csv"];
NSString *fileString = [NSString stringWithContentsOfFile:pathToFile encoding:NSUTF8StringEncoding error:nil];
if (!fileString) {
NSLog(@"Error reading file.");
}
NSArray *array = [fileString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
for(int i=0; i<[array count]; i++){
//
}
Run Code Online (Sandbox Code Playgroud) 我在我的项目中的两个视图控制器ViewController,SettingsView.我在这里尝试更新ViewController's标签,当我点击SettingsView's后退按钮时.NSLog工作正常,但标签没有更新......请帮帮我......
SettingsView.m
-(IBAction)backToMain:(id) sender {
//calling update function from ViewController
ViewController * vc = [[ViewController alloc]init];
[vc updateLabel];
[vc release];
//close the SettingsView
[self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
ViewController.m
- (void)updateLabel
{
NSLog(@"Iam inside updateLabel");
self.myLabel.text = @"test";
}
Run Code Online (Sandbox Code Playgroud)
你能告诉我我的代码有什么问题吗?谢谢!
我正在使用Xcode 4.3.2,如何在每天早上6点设置本地通知"dateToFire"?
-(void)notification
{
UILocalNotification *localNotification = [[[UILocalNotification alloc] init] autorelease];
if (!localNotification)
return;
// Current date
NSDate *date = [NSDate date];
NSDate *dateToFire = //Everyday: 6AM;
// Set the fire date/time
[localNotification setFireDate:dateToFire];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
[localNotification setAlertBody:@"Notification" ];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self notification];
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个新的iPhone应用程序,在这里,我已经从本地解析了一个'csv'文件,并与我一起工作.当我尝试以编程方式从服务器下载'csv'文件时,它没有为我锻炼.请你帮助我好吗?
从本地文件加载数据(工作正常)
- (void)viewDidLoad
{
[super viewDidLoad];
NSString * file = [[NSBundle bundleForClass:[self class]] pathForResource:@"sample" ofType:@"csv"];
NSStringEncoding encoding = 0;
NSString * csv = [NSString stringWithContentsOfFile:file usedEncoding:&encoding error:nil];
NSArray *fields = [csv CSVComponents];
NSLog(@"fields: %@", fields); //getting the result content
}
Run Code Online (Sandbox Code Playgroud)
从服务器下载文件(失败)
-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"connectionDidFinishLoading"); //nothing showing here
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *fullName = [NSString stringWithFormat:@"quotes.csv"];
NSString *fullFilePath = [NSString stringWithFormat:@"%@/%@",docDir,fullName];
[receivedData writeToFile:fullFilePath atomically:YES];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"data: …Run Code Online (Sandbox Code Playgroud) 如何以编程方式更改UISegmentedControl标题?请你帮助我好吗?
@synthesize filterControl; //UISegmentedControl
- (void)viewDidLoad
{
[super viewDidLoad];
filterControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"ALL",@"PROFIT",@"LOSS", nil]]; //not working
}
Run Code Online (Sandbox Code Playgroud)