如果我使用以下代码:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm"];
NSDate *myDate = [dateFormatter dateFromString:@"2010-01-28T15:22:23.863"];
NSLog(@"%@", [dateFormatter stringFromDate:myDate]);
Run Code Online (Sandbox Code Playgroud)
它成功地转换为一个Date对象,但是,我似乎无法以任何其他方式格式化它yyyy-MM-dd'T'HH:mm,即记录的是什么2010-01-28T15:22:23
如果我更改dateFormat以说[dateFormatter setDateFormat:@"yyyy-MMMM-d'T'HH:mm"];Date对象为null ...
所以我的最终问题是如何格式化SQL数据库中的ISO8601时间戳,以便使用,例如,NSDateFormatterMediumStyle返回"2010年1月1日"?
一个看似简单的问题......我怎样才能返回任何指定月份的天数列表?
NSDate *today = [NSDate date]; //Get a date object for today's date
NSCalendar *c = [NSCalendar currentCalendar];
NSRange days = [c rangeOfUnit:NSDayCalendarUnit
inUnit:NSMonthCalendarUnit
forDate:today];
Run Code Online (Sandbox Code Playgroud)
我基本上想要使用它,但取而代之today的是1月,所以我可以返回所有那些日子
UIViewAnimationTransitionCurlUp然而,我有一个工作过渡使用,我希望动画中途停止,就像地图应用程序...有关如何实现这一点的任何想法?
作为一种验证形式,是否有任何方法可以防止在按下"确定"按钮时解除警报视图?
场景:我在alertview中有2个文本字段用于用户名/密码.如果两者都为空并且用户按下"确定",我不希望该警报被解除.
我构建了一个包含5个以上标签的标签栏,余数自动添加到"更多"视图中.这很好,但与此同时,用户可以"编辑"应用程序选项卡的配置.
我不希望用户能够这样做.有没有办法阻止用户这样做?
这是我的场景:我有一个包含2个值的字典项数组.
array = (
{
id = 1;
title = "Salon One";
},
{
id = 2;
title = "Salon Two";
}
)
Run Code Online (Sandbox Code Playgroud)
我甚至不确定这是否可行,但是我可以将此数组传递给函数并根据字典值返回对象索引吗?
- (int)getObjectIndex:(NSMutableArray *)array byName:(NSString *)theName{
int index;
/* Pseudo Code*/
/*index = the index value in 'array' of objectForKey:@"title" = theName*/
return index;
}
Run Code Online (Sandbox Code Playgroud) 标题有点令人困惑......我会解释
我有一个NSMutableArray我填充NSMutableDictionary物体.我想要做的是在将字典对象添加到数组之前,我需要检查是否有任何字典包含的值等于已经设置的id.
例:
步骤1:单击一个按钮,设置对象的id以用于建立视图.
步骤2:在所述视图内按下另一个按钮以将其一些内容保存到字典中,然后将所述字典添加到数组中.但是,如果已建立的ID已作为其中一个字典键存在,请不要插入此字典.
以下是我目前无法使用的一些代码:
-(IBAction)addToFavorites:(id)sender{
NSMutableDictionary *fav = [[NSMutableDictionary alloc] init];
[fav setObject:[NSNumber numberWithInt:anObject.anId] forKey:@"id"];
[fav setObject:@"w" forKey:@"cat"];
if ([dataManager.anArray count]==0) { //Nothing exists, so just add it
[dataManager.anArray addObject:fav];
}else {
for (int i=0; i<[dataManager.anArray count]; i++) {
if (![[[dataManager.anArray objectAtIndex:i] objectForKey:@"id"] isEqualToNumber:[NSNumber numberWithInt:anObject.anId]]) {
[dataManager.anArray addObject:fav];
}
}
}
[fav release];
}
Run Code Online (Sandbox Code Playgroud) 我有一个返回字符串的查询,以及一个转义字符序列.(例如"美国")
我stringByReplacingOccurrencesOfString以这种方式使用:
[theCountry stringByReplacingOccurrencesOfString:@"\"" withString:@""];
Run Code Online (Sandbox Code Playgroud)
但它仍然留下一组报价.如果我再次尝试删除它们的方法:
[theCountry stringByReplacingOccurrencesOfString:@""" withString:@""];
Run Code Online (Sandbox Code Playgroud)
我会有一套不完整的引号......我需要摆脱斜线和双引号.
有什么想法吗?
我目前能够成功访问并从中获取数据peoplePickerNavigationController,但我想要做的是访问联系人的电子邮件地址,然后在按下联系人姓名时解除模态窗口.
场景:
"Button is clicked to add a contact
AddressBook Modal Window slides into view
Name of Contact is pressed
If available, the contact's email address is stored in an array
Dismiss modal window"
Run Code Online (Sandbox Code Playgroud)
我目前的代码包括:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
ABMultiValueRef container = ABRecordCopyValue(person, property);
CFStringRef contactData = ABMultiValueCopyValueAtIndex(container, identifier);
CFRelease(container);
NSString *contactString = [NSString stringWithString:(NSString *)contactData];
CFRelease(contactData);
NSLog(@"Value is: %@", contactString);
[self dismissModalViewControllerAnimated:YES];
return NO;
}
Run Code Online (Sandbox Code Playgroud) iphone ×6
objective-c ×6
nsdate ×2
addressbook ×1
curl ×1
iso8601 ×1
string ×1
tabbar ×1
transition ×1
uialertview ×1