我想在表视图的节头中显示格式化日期.
我使用了以下代码.但它抛出异常*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath dateSectionIdentifier not found in entity <NSSQLEntity Expense id=1>'.
猜测添加排序描述符时会出现异常.
NSMutableArray *sortDescriptors = [[NSMutableArray alloc] initWithCapacity:20];
NSSortDescriptor *mainSortDescriptor = [[NSSortDescriptor alloc] initWithKey:dateSectionIdentifier ascending:NO];
[sortDescriptors addObject:mainSortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
Run Code Online (Sandbox Code Playgroud)
//Expense.h
NSString *dateSectionIdentifier;
Run Code Online (Sandbox Code Playgroud)
//Expense.m
@dynamic dateSectionIdentifier
-(NSString *)dateSectionIdentifier{
[self willAccessValueForKey:@"dateSectionIdentifier"];
NSString *tempDate = [self primitiveDateSectionIdentifier];
[self didAccessValueForKey:@"dateSectionIdentifier"];
if(!tempDate){
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"d MMMM yyyy"];
tempDate = [dateFormatter stringFromDate:[self date]];
[self setPrimitiveDateSectionIdentifier:tempDate];
[dateFormatter release];
}
return tempDate;
}
Run Code Online (Sandbox Code Playgroud) UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [self.datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"Did you forget something?";
notif.alertAction = @"Show me";
Run Code Online (Sandbox Code Playgroud)
如果用户点击"showme"应用程序应该打开,他应该收到警报.我应该在哪里写这个代码?如果可能的话,有人请给我一些代码
当用户点击图片时,图像应该被发送到他的邮件.我希望这发生在后台,所以我使用SKPSMTPMessage.如果用户在上一个图片被发送/ Uploaded之前点击图片,我会收到错误.我想我会使用GCD序列化这个,但我无法解决它.
- (IBAction)snapStillImage:(id)sender
{
//code after taking the picture
if([uploadMethod isEqualToString:@"Mail"]){
time_t unixTime = (time_t) [[NSDate date] timeIntervalSince1970];
NSString *timestamp=[NSString stringWithFormat:@"%ld",unixTime];
NSData *jpgData = UIImageJPEGRepresentation(image, 0.5);
[jpgData writeToFile:[self documentsPathForFileName:timestamp] atomically:YES];
[self.imagesArray addObject:timestamp];
[self sendMail];
}
-(void)sendMail{
dispatch_queue_t myFifoQueue = dispatch_queue_create("com.xxxx.uploadpictures",DISPATCH_QUEUE_SERIAL);
if(!self.imagesArray.count == 0){
for(NSString *str in self.imagesArray){
dispatch_async(myFifoQueue,^{
[self sendMailWith:str];
});
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,如果用户输入数据,行将使用该数据更新
我可以使用单个按钮说"删除",单击该按钮会立即删除tableview中的所有行.
-(void)save:(id)sender
{
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &expenseDB) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO ADDEXPENSE(date, description, category, amount) VALUES (\"%@\", \"%@\", \"%@\",\"%@\")", fieldOne.text, fieldTwo.text,fieldThree.text , fieldFour.text];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(expenseDB, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
status.text = @"saved"
}
else
{
status.text = @"Failed"
}
sqlite3_finalize(statement);
sqlite3_close(expenseDB);
}
}
Run Code Online (Sandbox Code Playgroud)
这个方法对我来说很好.但是如何将它保存为日期而不是字符串?我尝试了几种方法,但没有为我工作.因为我是编码的新手.有人请帮我一段代码uuuuuuuuu这是我使用的日期选择器.
UIDatePicker *picker = (UIDatePicker *)sender;
NSDate *dateSelected = [picker date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] …Run Code Online (Sandbox Code Playgroud)