我有在iTunes商店它显示了一些应用程序UILabel和UIWebView上UIAlertView.根据会议视频,addSubView为UIAlertView不起作用.他们已经谈过了ContentView.但在GM种子SDK中,我找不到该属性,似乎没有别的办法.
我唯一能做的就是创建一个自定义子类UIView并使其工作UIAertView.你能建议其他简单的解决方案吗?
谢谢您的帮助.
我正在获取UILabel的宽度[在文本设置之后]:
myUILabel.frame.width
Run Code Online (Sandbox Code Playgroud)
但它始终具有相同的宽度,无论它是否包含String:"Hello."或String : "Hello everyone on this planet.". 但是UILabel需要有更大的宽度和第二个String.
我在Swift(XCode 6.2)中创建了一个非常简单的单视图应用程序,它包含2个按钮"blackButton"和"whiteButton".单击blackButton后,它会将View的背景颜色更改为Black,并在单击whiteButton时将背景更改为白色.有谁能建议任何可能的方法来做到这一点?
//beginning
import UIKit
class ViewController: UIViewController {
@IBAction func blackButton(sender: AnyObject) {
}
@IBAction func whiteButton(sender: AnyObject) {
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Swift语言和方法创建一个UITableViewController
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell?
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
NSIndexPath?在Swift中没有成员名称'row'错误
而且我不明白为什么.
这是我的代码
import UIKit
class DPBPlainTableViewController: UITableViewController {
var dataStore: NSArray = NSArray()
override func viewDidLoad() {
super.viewDidLoad()
self.dataStore = ["one","two","three"]
println(self.dataStore)
}
// #pragma mark - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return self.dataStore.count …Run Code Online (Sandbox Code Playgroud) 我试图将一个双倍增加到一个整数,
var numberOfBottles = totalVolume / volumeEachBottles
Run Code Online (Sandbox Code Playgroud)
例如numberOfBottles = 275.0 / 250.0
,这会给我1.1,我需要它来围绕2
我试图在用户单击UILocalNotification时从swift中的app delegate加载特定的ViewController.我已经发现在这个函数中调用了它:
func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试访问其中一个打开的ViewControllers时,我认为它返回null,因为我的应用程序正在崩溃.这是我正在尝试的:
var rootViewController = self.window!.rootViewController
var storyBoard = rootViewController.storyboard
var setViewController = storyBoard.instantiateViewControllerWithIdentifier("CurrentShows") as ViewController_CurrentShows
rootViewController.navigationController.popToViewController(setViewController, animated: false)
setViewController.reloadData()
Run Code Online (Sandbox Code Playgroud)
它在popToViewController行崩溃了.
最后说
我有一个包含B实例的A类.在A类中,我将A的一个函数作为选择器传递给一个B的方法.B使用这个选择器来注册通知.但是,当通知进入时,它无法运行选择器并显示"无法识别的选择器发送到实例".如果我把我想要在B级做的所有事情都转移到A级,那就有用了.但是,我希望它们分开,以使它看起来更有条理.我对Objective-C和Swift相当新,因此,在这种情况下,我不知道如何将selector作为参数传递.Swift中的答案会很棒.
ViewController.swift
class ViewController: UIViewController {
var sessionCtrl : GKSessionControllerH!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
sessionCtrl = GKSessionControllerH()
// register notifications
registerNotification()
}
func registerNotification() {
sessionCtrl.registerNotification(GKGesture.Up, gestureHandler: "gestureUpHandler")
}
func gestureUpHandler() {
dispatch_async(dispatch_get_main_queue()) {
self.slidesViewCtrl!.prevPage()
}
}
}
Run Code Online (Sandbox Code Playgroud)
GKSessionControllerH.swift
class GKSessionControllerH: NSObject, WCSessionDelegate {
func handleGestureContent(content : AnyObject?) {
// retrieve gesture
let gesture = GKGesture(rawValue: content as! String)!
print("Handheld device receives \(gesture)")
// post …Run Code Online (Sandbox Code Playgroud) 我想创建一个protocol强制执行某个案例的所有enums符合此要求的案例protocol.
例如,如果我有enum这样的:
enum Foo{
case bar(baz: String)
case baz(bar: String)
}
Run Code Online (Sandbox Code Playgroud)
我想扩展它protocol,增加另一个案例:
case Fuzz(Int)
Run Code Online (Sandbox Code Playgroud)
这可能吗?
对于那些不知道我在说什么的人,Xcode 6.0增加了新功能,IBDesignable和IBInspectable.
使用IBInspectable属性标记自定义视图时,这些属性将显示在IB中的"属性"检查器中.
同样,当您使用IBDesignable标记自定义UIView子类时,Xcode会编译您的视图并调用代码以在Xcode窗口中直接呈现视图对象,以便您可以看到它们的外观.
在自定义视图中添加IBDesignable和IBInspectable属性的技术在Swift和Objective-C中非常相似.IBInspectable属性显示在Interface Builder Attributes Inspector中,无论您使用哪种语言来定义它们.
我在Objective-C中创建了一个UIView类,并在Swift中创建了UIView的扩展,它将视图底层的borderWidth,cornerRadius,borderColor和layerBackgroundColor属性提升为视图的属性.如果更改属性,则扩展名/类别会根据需要键入转换,并将更改转发给图层.
IBInspectable部分运作良好.我看到并可以在IB属性检查器中设置新属性.
我可以在上周发誓,我的视图类别/扩展名上的IBDesignable属性也正常工作,我可以在IB中看到我的自定义UIView类别渲染,它具有更改的图层属性.本周它没有用.
我是产生幻觉的吗?
现有系统类的类别/扩展可以在使用IBDesignable设置时在Interface Builder中绘制自定义UI吗?
interface-builder ios xcode-storyboard ibdesignable ibinspectable
简单的问题.我得到了对下一个视图控制器执行segue的按钮.我想写UI XCTest告诉我它是否打开了我想要的视图控制器.
ios ×8
swift ×8
appdelegate ×1
double ×1
enums ×1
ibdesignable ×1
ios7 ×1
objective-c ×1
protocols ×1
rounding ×1
selector ×1
uialertview ×1
uilabel ×1
uitableview ×1
xctest ×1