NSDate作为customMethod中的参数 [英] NSDate as argument in customMethod
本文介绍了NSDate作为customMethod中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将自定义方法( - (void)loadXML {}
)定义到我的appDelegate中。
现在我想在几个viewControllers中使用它;现在我正在使用本地NSDate对象。
I've defined my custom method ( -(void)loadXML {}
) into my appDelegate.
Now I'd like to use it in severals viewControllers; Right now I'm using local NSDate objects.
NSDate *todayDate = [NSDate date];
NSString *XMLUrl = @"http://localhost/MyApp/GetXML?&aDate=";
NSString *urlString = [NSString stringWithFormat:@"%@%@", XMLUrl, todayDate];
tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:urlString]];
而不是'todayDate'我想要'selectedDate';另外我如何在我的方法中添加一个bool,需要在我的方法中加入一些条件?
instead of 'todayDate' I'd like to have 'selectedDate'; also how I add a bool to my method, need to have some conditions into my method?
推荐答案
这是你可以做的:
NSDate *selectedDate = ???????; // set this to whatever you want selectedDate to be
BOOL myBoolean = YES;
NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat: @"yyyy-MM-dd"]; // or whatever format you wish
NSString *urlString =
[NSString stringWithFormat:@"http://localhost/MyApp/GetXML?BOOL=%@&aDate=%@",
(myBoolean ? @"YES" : @"NO"),
[dateFormatter stringFromDate: selectedDate]];
tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:urlString]];
[dateFormatter release]; // don't forget to release, if not using ARC
为了你的利益,我是向您展示如何使用 NSDateFormatter 和通用C三元条件。
And for your benefit, I'm showing you how to use a NSDateFormatter and a generic C ternary conditional.
我希望这能帮到你!
这篇关于NSDate作为customMethod中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文