我已经尝试这样做了两个星期,并且发现它不起作用的原因:
弃用的API
不推荐使用以下API:
UIViewController接口方向的方法和属性.如统一故事板中的通用应用程序所述,特征和大小类会替换它们.
我需要的是:a FirstViewController,这是rootViewController我的navigationController.本FristViewController应只在人像模式(不是永远永远永远显示在景观)可用.
然后在导航堆栈中有一些中间ViewControllers(支持两种方向),直到我到达a LastViewController,这应该仅在LandscapeRight模式下可用(并且永远不会在纵向或其他模式下).
我一直在尝试使用以下内容CustomNavigationController,但显然iOS8中的内容发生了变化,我无法让它工作:
- (BOOL)shouldAutorotate { // Available in iOS 6.0 and later
return YES; // // May use topViewController's, but in this app it always returns YES
}
- (NSUInteger)supportedInterfaceOrientations { // Available in iOS 6.0 and later
if (self.topViewController != nil)
return [self.topViewController supportedInterfaceOrientations];
else
return [super supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { // Available …Run Code Online (Sandbox Code Playgroud) import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var helloButton: NSButton!
@IBAction func showAlert(sender: AnyObject) {
var alert = UIAlertController(title: "Hello!", message: "Hello, world!",
preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
self.helloButton.setTitle("Clicked", forState: UIControlState.Normal)
}
Run Code Online (Sandbox Code Playgroud) 我需要从json文件加载一个元组数组.我尝试了以下但它不起作用.
我的json文件是:
{"破":[(1,1),(1,2),(2,2),(3,1)]}
然后我loadsjsonfrombundle用来从JSON加载数据如下:
let broken = [(Int, Int)]!
if let dictionary = Dictionary<String, AnyObject>.loadsjsonfrombundle(filename) {
broken = (dictionary["broken"]) as Array
}
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
谢谢.
有没有办法判断目前是否有UIAlertView实例显示?因为可以UIAlertView在同一窗口级别显示多个.
if ([self isAlertViewShowing]) {
// do not show UIAlertView again.
} else {
// show your UIAlertView.
}
Run Code Online (Sandbox Code Playgroud)
希望有一种叫做isAlertViewShowing或其他的方法.
例如像这段代码.
Button button1 = (Button)findViewById(R.id.button1);
Run Code Online (Sandbox Code Playgroud)
用于的按钮中的括号()是什么?
如果用户在下载后第一次打开应用程序,那么我想显示带有教程的视图控制器,然后转到主应用程序的View Controller.但是如果用户之前已经访问过app,那么请转到主视图控制器.
如何在AppDelegate中实现该检查?
我不是编程专家,但我修改了一个代码来从Facebook SDK获取用户个人资料图片.问题是我在图像中得到一个问号(profilePicture.image).谁能告诉我这里发生了什么?
另外,我不知道如何在viewController中调用此函数来获取图像?目前我在函数内部直接添加了profilePicture.image.
func getProfPic(fid: String) -> UIImage? {
if (fid != "") {
var imgURLString = "http://graph.facebook.com/" + fid + "/picture?type=large" //type=normal
var imgURL = NSURL(string: imgURLString)
var imageData = NSData(contentsOfURL: imgURL!)
var image = UIImage(data: imageData!)
profilePicture.image = image // Returned image is Question mark
return image
}
return nil
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Swift 4.2运行Xcode 10 beta.Xcode想要将我的Xcode 9.4.1与Swift 4.1代码转换为Swift 4.2语法.这些变化都是UIView.animate(... options: ...).
我使用的选项.curveEaseIn之前工作正常,但它想要改变它们UIView.AnimationOptions.curveEaseIn.
Swift的ENUM类型推断发生了什么?