我有一个来自UIDatepicker的NSDate.
IBOutlet UIDatePicker *dueDate;
NSDate *selectedDate = [dueDate date];
Run Code Online (Sandbox Code Playgroud)
如何dueDate以形式检索月份int?(1月1日,2月2日等)
我正在看的功能:
-(void)viewDidLoad {
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"statedictionary" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
self.statesZips = dictionary;
[dictionary release];
NSArray *components = [self.stateZips allKeys];
NSArray *sorted = [components sortedArrayUsingSelector:@selector(compare:)];
self.States = sorted;
NSString *selectedState = [self.states objectAtIndex:0];
NSArray *array = [stateZips objectForKey: selectedState];
self.zips = array;
}
Run Code Online (Sandbox Code Playgroud)
为什么分配NSDictionary,然后分配给一个名为*dictionary的指针,然后分配给实例变量stateZips?为什么不分配它并将其直接分配给实例变量并节省创建和释放另一个NSDictionary的内存?始终遵循相同的方法,包括后来在NSArray的此功能中......
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
self.statesZips = dictionary;
[dictionary release];
Run Code Online (Sandbox Code Playgroud)
此外,此排序按字母顺序放置哈希表(字典)中的键.我不确定我理解这一行:
NSArray *sorted = [components sortedArrayUsingSelector:@selector(compare:)];
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我在UIColor上创建一个类别来创建随机颜色.但是,从这段代码中,我会认为每次运行方法时'if'条件都是真的,而不仅仅是第一次.
我想我并没有真正理解静态变量.静态变量是否只设置一次,然后第二次运行该方法时,该行只是被忽略了?(第一次运行后种子会永远为是)?
@interface UIColor(Random)
+(UIColor *)randomColor
{
static BOOL seeded = NO;
if (!seeded)
{
seeded = YES;
srandom(time(NULL));
}
CGFloat red = (CGFloat)random()/(CGFloat)RAND_MAX;
CGFloat green = (CGFloat)random()/(CGFloat)RAND_MAX;
CGFloat blue = (CGFloat)random()/(CGFloat)RAND_MAX;
return [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个viewController的实例,然后尝试设置它的属性文本,UILabel.
BoyController *boyViewController = [[BoyController alloc] initWithNibName:@"BoyView" bundle:nil];
NSString *newText = [astrology getSignWithMonth:month withDay:day];
boyViewController.sign.text = newText;
NSLog(@" the boyviewcontroller.sign.text is now set to: %@", boyViewController.sign.text);
[newText release];
Run Code Online (Sandbox Code Playgroud)
我尝试过这个,但它不起作用......
所以我尝试了以下方法:
BoyController *boyViewController = [[BoyController alloc] initWithNibName:@"BoyView" bundle:nil];
UILabel *newUILabel = [[UILabel alloc] init];
newUILabel.text = [astrology getSignWithMonth:month withDay:day];
boyViewController.sign = newUILabel;
NSLog(@" the boyviewcontroller.sign.text is now set to: %@", newUILabel.text);
[newUILabel release];
Run Code Online (Sandbox Code Playgroud)
但无济于事..
我不知道为什么我不能在boyViewController中设置UILabel"sign"的text属性.
我正在阅读Python教程,然后我进入了关于模块的部分.
我在Users/Me/code/Python中创建了一个fibo.py文件
现在我回到解释器中,我似乎无法导入模块,因为我不明白如何导入相对(或绝对)路径.
我也对如何以及是否修改PYTHONPATH和/或sys.path感到困惑.
所有其他'导入模块'问题似乎都在这里