小编iel*_*ani的帖子

添加彩色图像作为导航栏中的右侧栏按钮项

我添加了一个带有彩色背景图像的右侧导航栏项目:

let rightButton = UIBarButtonItem(image: UIImage(named: "avatar")!,
                                  style: UIBarButtonItemStyle.Plain, 
                                  target: self,     
                                  action: #selector(self.rightNavBarItemAction))

navigationItem.rightBarButtonItem = rightButton
Run Code Online (Sandbox Code Playgroud)

我没有将图像作为按钮的背景(颜色),而是得到一个白色的占位符。

uinavigationcontroller uinavigationitem ios swift

2
推荐指数
1
解决办法
2682
查看次数

使用 Openweathermap 获取名称包含空格的城市的天气

我正在尝试使用以下代码使用Openweathermap获取城市的天气:

func getWeatherByCity(city: String) {
    if let weatherRequestURL = NSURL(string: "\(openWeatherMapBaseURL)?APPID=\(openWeatherMapAPIKey)&q=\(city)") {
        getWeather(weatherRequestURL: weatherRequestURL)
    }
}
Run Code Online (Sandbox Code Playgroud)

(完整教程http://www.globalnerdy.com/2016/04/02/how-to-build-an-ios-weather-app-in-swift-part-1-a-very-bare-bones-天气应用程序/ )

api 适用于不包含空格的城市名称。

即使在主页http://openweathermap.org/ 上,寻找 san francisco 也没有结果。

这里缺少什么?

weather-api ios swift openweathermap

2
推荐指数
1
解决办法
4490
查看次数

在 Swift 中进行节流而不进行反应

是否有一种简单的方法可以在反应式编程中实现 Throttle 功能,而无需使用 RxSwift 或类似框架。

我有一个 textField 委托方法,我不想在每次插入/删除字符时触发它。

如何使用香草粉底做到这一点?

throttling reactive-programming ios swift

2
推荐指数
1
解决办法
3693
查看次数

如何从包含Swift参数的枚举的枚举中生成随机变量?

鉴于以下枚举:

enum GameLevel {
    case Level(Int)
    case TutorialLevel, BossLevel
}
Run Code Online (Sandbox Code Playgroud)

如何GameLevel在Swift中生成类型的随机变量?

swift

1
推荐指数
1
解决办法
1510
查看次数

Swift中的元组的多级排序数组

我想[(Int,Int)]基于.1元素(从大到小)对元组数组进行排序,以便进行相等比较.0(从最小到最大)

我用这个:

myArray.sort{ $0.0 != $1.0 ? $0.1 > $1.1 : $0.0 < $1.0}
Run Code Online (Sandbox Code Playgroud)

但它不起作用

tuples swift

0
推荐指数
1
解决办法
1539
查看次数