我目前正在我的应用程序中打开链接WebView,但我正在寻找一个选项来在Safari中打开链接.
当我尝试将我的应用程序提交到应用程序商店时,我总是收到此消息.
这是一张消息的图片:

如果有人可以帮我解决这个问题,那么我可以将我的应用程序提交到商店.
目前我的ActionSheet遇到了大麻烦.在iPhone上它运行良好,但在iPad上它只会崩溃
我用一个按钮创建一个新项目
import UIKit
extension ViewController : UIActionSheetDelegate {
func actionSheet(actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {
if actionSheet.tag == 0 {
if buttonIndex == 1 {
// doing something for "product page"
} else if (buttonIndex == 2) {
// doing something for "video"
}
}
}
}
class ViewController: UIViewController, UIActionSheetDelegate {
@IBAction func test(sender: AnyObject) {
let systemVersion: NSInteger = (UIDevice.currentDevice().systemVersion as NSString).integerValue
if systemVersion < 8 {
// iOS7:
let action:UIActionSheet = UIActionSheet(title: "Change Map Type", delegate: …Run Code Online (Sandbox Code Playgroud) 我设法在Swift中获得了注释引脚的自定义图标,但现在我仍然使用2个不同的图像进行不同的注释.现在,按钮会向地图添加注释.应该有另一个按钮,它还添加了注释,但带有另一个图标.
有没有办法使用reuseId?
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var Map: MKMapView!
@IBAction func btpressed(sender: AnyObject) {
var lat:CLLocationDegrees = 40.748708
var long:CLLocationDegrees = -73.985643
var latDelta:CLLocationDegrees = 0.01
var longDelta:CLLocationDegrees = 0.01
var span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
var location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(lat, long)
var region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
Map.setRegion(region, animated: true)
var information = MKPointAnnotation()
information.coordinate = location
information.title = "Test Title!"
information.subtitle = "Subtitle"
Map.addAnnotation(information)
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if !(annotation is MKPointAnnotation) …Run Code Online (Sandbox Code Playgroud) if (view.annotation.title as String!) == "Helgoland " {
currentLong = 7.889021
currentLat = 54.180210
url = "google.com"
let alertController: UIAlertController = UIAlertController(title: "Change Map Type", message: nil, preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction: UIAlertAction = UIAlertAction(title: "Back", style: UIAlertActionStyle.Cancel, handler: nil)
let button1action: UIAlertAction = UIAlertAction(title: "Product Page", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in
performSegueWithIdentifier("showShop", sender: self)
})
let button2action: UIAlertAction = UIAlertAction(title: "Video", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in
youtubeVideoID = "XX"
UIApplication.sharedApplication().openURL(NSURL(string: "http://www.youtube.com/watch?v=\(youtubeVideoID)"))
}) …Run Code Online (Sandbox Code Playgroud) 我尝试创建一个NavBar,到目前为止NavBar没有问题,但如果我尝试添加按钮和标题,我会被吸.
我的NavBar看起来像
let NameHeight = screenHeight * 0.09
let NameWidth = screenWidth
let navBar: UINavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: NameWidth, height: NameHeight))
self.view.addSubview(navBar)
Run Code Online (Sandbox Code Playgroud)
所以我尝试设置我的NavBar标题
navigationBar.topItem.title = "some title"
or
navigationBar.title = "some title"
Run Code Online (Sandbox Code Playgroud)
但都失败了.
此外,如果我尝试设置一个按钮
let btnName = UIButton()
btnName.setImage(UIImage(named: "imagename"), forState: .Normal)
btnName.frame = CGRectMake(0, 0, 30, 30)
btnName.addTarget(self, action: Selector("action"), forControlEvents: .TouchUpInside)
//.... Set Right/Left Bar Button item
let rightBarButton = UIBarButtonItem()
rightBarButton.customView = btnName
self.navigationItem.rightBarButtonItem = rightBarButton
Run Code Online (Sandbox Code Playgroud)
这不会给我一个错误,但按钮根本不显示
我在我的应用程序中下载了一些PDF文件,并希望在关闭应用程序时删除这些文件.
由于某种原因,它不起作用:
创建文件:
let reference = "test.pdf"
let RequestURL = "http://xx/_PROJEKTE/xx\(self.reference)"
let ChartURL = NSURL(string: RequestURL)
//download file
let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first! as NSURL
let destinationUrl = documentsUrl.URLByAppendingPathComponent(ChartURL!.lastPathComponent!)
if NSFileManager().fileExistsAtPath(destinationUrl.path!) {
print("The file already exists at path")
} else {
// if the file doesn't exist
// just download the data from your url
if let ChartDataFromUrl = NSData(contentsOfURL: ChartURL!){
// after downloading your data you need to save it to your destination url
if ChartDataFromUrl.writeToURL(destinationUrl, atomically: true) …Run Code Online (Sandbox Code Playgroud) 我目前试图找到一种方法删除,同时运行应用程序TabBar项目,我找到了启用或禁用它的方法,但没有完成删除它.
为了禁用它我做:

在ViewDidLoad中
if let tabBarItem = self.tabBarController?.tabBar.items?[3] as? UITabBarItem {
tabBarItem.enabled = false
}
Run Code Online (Sandbox Code Playgroud)
这很好,但仍然用户可以看到TabBar项目,我只是完成删除它,有没有办法?
我想通过Parse触发TabBarItem,如果我将Parse Data设置为true,它应该显示不应该的其他方式.
我遇到了一个小问题,让我从代码开始
class ViewController: UIViewController {
@IBOutlet weak var LBoutput: UILabel!
@IBAction func BTclick(sender: AnyObject) {
var url = NSURL(string: "http://google.com")
println("test0")
let getdata = NSURLSession.sharedSession().dataTaskWithURL(url){(data ,response , error) in
var htmlContent = NSString(data: data, encoding: NSUTF8StringEncoding)
println("test1")
println("test2")
self.LBoutput.text = "test6"
}
println("test3")
getdata.resume()
println("test4")
LBoutput.text = "test5"
}
Run Code Online (Sandbox Code Playgroud)
这段代码在控制台中给我一个输出
test0
test3
test4
test1
test2
此外,标签没有时间更新为"test5",但更新为"test6"的标签需要30秒.
我不知道为什么这需要这么长时间,任何人都有想法?
我尝试在我的WebView上使用一些新的JavaScript
stringByEvaluatingJavaScriptFromString 功能
我不熟悉语法,所以我试过
func stringByEvaluatingJavaScriptFromString( "document.documentElement.style.webkitUserSelect='none'": String) -> String?
Run Code Online (Sandbox Code Playgroud)
如下所示https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/index.html#//apple_ref/occ/instm/UIWebView/stringByEvaluatingJavaScriptFromString:但是我收到"预期"的错误".分隔器"