我有一个具有一些表单字段的应用程序。提交表单后,它将数据写入我的核心数据对象。但是,当再次提交表单时,它会覆盖现有数据而不是附加到它,这正是我想要发生的情况。
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
let managedContext = appDelegate.persistentContainer.viewContext
let userEntity = NSEntityDescription.entity(forEntityName: "User", in: managedContext)
let newUser = NSManagedObject(entity: userEntity! , insertInto: managedContext)
newUser.setValue(titleField, forKey: "title")
newUser.setValue(firstNameField, forKey: "firstName")
newUser.setValue(lastNameField, forKey: "lastName")
newUser.setValue(emailField, forKey: "email")
newUser.setValue(affiliatedOrgField, forKey: "affiliatedOrg")
newUser.setValue(ukRegionField, forKey: "ukRegion")
newUser.setValue(privacyChecked, forKey: "privacyPolicy")
do {
try managedContext.save()
} catch let error as NSError {
print("Could not save. \(error), \(error.userInfo)")
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用
let userEntity = NSEntityDescription.insertNewObject(forEntityName: "User", into: managedContext)
let newUser = …Run Code Online (Sandbox Code Playgroud) 在撰写这篇文章之前,我对UserNotification Framework进行了大量研究,取代了IOS 10中的UILocalNotification.我也按照本教程学习了有关这一新功能的所有内容:http://useyourloaf.com/blog/local-notifications-with- ios-10 /.
今天我遇到了很多麻烦来实现这些琐碎的通知,因为它是最近的新功能,我找不到任何解决方案(特别是在目标C中)!我目前有2个不同的通知,一个警报和一个徽章更新.
在将我的手机从IOS 10.1升级到10.2之前,我在Appdelegate上发出警报,当用户手动关闭应用程序时,该警报立即被触发:
-(void)applicationWillTerminate:(UIApplication *)application {
NSLog(@"applicationWillTerminate");
// Notification terminate
[self registerTerminateNotification];
}
// Notification Background terminate
-(void) registerTerminateNotification {
// the center
UNUserNotificationCenter * notifCenter = [UNUserNotificationCenter currentNotificationCenter];
// Content
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = @"Stop";
content.body = @"Application closed";
content.sound = [UNNotificationSound defaultSound];
// Trigger
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO];
// Identifier
NSString *identifier = @"LocalNotificationTerminate";
// création de la requête …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我想滑入和滑出视图控制器。因此,为此我正在使用自定义过渡,但应用程序崩溃了。我无法找出确切的问题所在。请帮帮我。
代码
class CustomTransition: NSObject, UIViewControllerAnimatedTransitioning,UIViewControllerTransitioningDelegate {
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
// get reference to our fromView, toView and the container view that we should perform the transition in
let container = transitionContext.containerView
let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from)! // the app crashes here saying nil founded
let toView = transitionContext.view(forKey: UITransitionContextViewKey.to)!
let animationDuration = self .transitionDuration(using: transitionContext)
let offScreenRight = CGAffineTransform(translationX: container.frame.width, y: 0)
let offScreenLeft = CGAffineTransform(translationX: -container.frame.width, y: 0)
toView.transform = offScreenRight
// add the both views …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建具有样式UIAlertControllerStyleActionSheet(以前称为UIActionSheet)的自定义UIAlertController,并且遇到了很多麻烦,无法简单地对其进行自定义。我希望UIAlertAction 在左侧包含一个图像并减小按钮的大小。
我知道这是可行的:
(这正是我想要的)
我搜索了几个小时,但在互联网上找不到任何可以帮助我完成此简单任务的tut。另外,由于UIActionSheet自IOS 9起就已弃用,因此每当我尝试查找解决方案时,它便不再可用。另外,我读到UIAlertController不打算被子类化。
有谁知道如何实现警报的轻量级定制?我是否必须对UIView进行细分才能制作自己的警报表?
这是我用于设置应用程序背景图像的代码。
import 'package:flutter/material.dart';
void main() => runApp(Calculator());
class Calculator extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/Background_1.jpg"),
fit: BoxFit.cover,
),
),
child: null,
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在尝试运行代码时遇到的错误!
> I/flutter (10809): ??? EXCEPTION CAUGHT BY WIDGETS LIBRARY
> ???????????????????????????????????????????????????????????? I/flutter
> (10809): The following assertion was thrown building Calculator:
> I/flutter (10809): MediaQuery.of() called with a context that does not
> contain a MediaQuery. I/flutter …Run Code Online (Sandbox Code Playgroud)