我试图使用'if'语句来确定单击了哪个元素.
基本上我正在尝试编写以下内容:
if (the element clicked is '#news_gallery li .over') {
var article = $('#news-article .news-article');
} else if (the element clicked is '#work_gallery li .over') {
var article = $('#work-article .work-article');
} else if (the element clicked is '#search-item li') {
var article = $('#search-item .search-article');
};
Run Code Online (Sandbox Code Playgroud)
什么是适当的jQuery语法?提前谢谢了.
我试图使用以下代码弹出到根视图控制器:
self.navigationController!.popToRootViewController(animated: true)
Run Code Online (Sandbox Code Playgroud)
这通常有效,但在当前视图是模态时尝试使用此代码时出错.在这种情况下,如何弹回到根视图控制器?
提前致谢.
我正在尝试将内容加载到UIWebView中,当在模拟器中进行测试时,我得到的是一个白色屏幕,并且控制台中出现以下错误:
NSURLConnection finished with error - code -1100
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?我目前的Swift代码是:
class ViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
webView.allowsInlineMediaPlayback = true;
webView.mediaPlaybackRequiresUserAction = false;
webView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "www/index", ofType: "html")!)))
let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
statusBar?.backgroundColor = UIColor.clear
}
}
Run Code Online (Sandbox Code Playgroud)
只是为了澄清,这段代码通常适用于我,但我找不到任何与错误-1100相关的在线内容.非常感谢.
我有一个具有一些表单字段的应用程序。提交表单后,它将数据写入我的核心数据对象。但是,当再次提交表单时,它会覆盖现有数据而不是附加到它,这正是我想要发生的情况。
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) 以前,将本地html内容加载到UIWebView时,它将在后台自动运行localhost / server。例如,此服务器仿真将使我能够通过json加载动态内容。下面的示例代码;
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
webView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "www/index", ofType: "html")!)))
}
Run Code Online (Sandbox Code Playgroud)
我现在正在尝试将其实现到WKWebView中。我可以加载本地html内容,但是与UIWebView不同,WKWebView不模拟localhost / server,因此我无法做以前的事情,例如用json动态加载内容等。我将如何通过localhost运行本地html内容?如果UIWebView自动具有该功能,那么WKWebView当然应该正确吗?下面的代码。
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
webView.load(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "www/index", ofType: "html")!)))
}
Run Code Online (Sandbox Code Playgroud)
注意:我正在为此使用Xcode 9,因此通过Storyboard添加了WKWebview并将其引用为插座。
在此先感谢任何可以帮助我的人。
我正在尝试创建一些通过线连接的可拖动的UIViews.见下图:
我可以通过创建一个类来创建可拖动的圆圈,该类是UIView的子类并覆盖绘制函数
override func draw(_ rect: CGRect) {
let path = UIBezierPath(ovalIn: rect)
let circleColor:UIColor
switch group {
case .forehead:
circleColor = UIColor.red
case .crowsFeetRightEye:
circleColor = UIColor.green
case .crowsFeetLeftEye:
circleColor = UIColor.blue
}
circleColor.setFill()
path.fill()
}
Run Code Online (Sandbox Code Playgroud)
然后为拖动添加平移手势识别器
func initGestureRecognizers() {
let panGR = UIPanGestureRecognizer(target: self, action: #selector(DragPoint.didPan(panGR:)))
addGestureRecognizer(panGR)
}
@objc func didPan(panGR: UIPanGestureRecognizer) {
if panGR.state == .changed {
self.superview!.bringSubview(toFront: self)
let translation = panGR.translation(in: self)
self.center.x += translation.x
self.center.y += translation.y
panGR.setTranslation(CGPoint.zero, in: self)
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我完全不知道如何进行连接线并在拖动时将起点/终点点到相应的圆圈.有没有人可以帮助或指出我正确的方向?
我正在使用 PHP 7 运行 laravel 服务器。我试图使用以下命令来请求文件:
require __DIR__.'/../bootstrap/autoload.php';
Run Code Online (Sandbox Code Playgroud)
我运行此脚本的文件位于名为 public 的文件夹中。因此__DIR__应该等于:
www.mydomain.com/myserver/public/index.php
Run Code Online (Sandbox Code Playgroud)
脚本应创建的路径应该是:
www.mydomain.com/myserver/bootstrap/autoload.php
Run Code Online (Sandbox Code Playgroud)
然而,它不是动态创建正确的路径,而是将“/../”视为文字目录,而不是告诉它返回一个目录。所以我要返回的路径是:
www.mydomain.com/myserver/public/../bootstrap/autoload.php
Run Code Online (Sandbox Code Playgroud)
有什么想法为什么会发生这种情况吗?提前谢谢了。