是否可以通过索引获取字典键?
我正在尝试使用字典作为选择器视图的数据源,并希望在以下委托方法中访问它:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if (component == 0){
return [NSString stringWithFormat:@"%@",[myDict // how to get the key]];
}
Run Code Online (Sandbox Code Playgroud)
编辑 -
myDict是这样的:
第1项
第2项
我想使用myDict作为具有2个部分的选择器视图的数据源:
第0节= myDict键(第1项,第2项)
第1部分=所选第0行的相应myDict值(子项1,子项2)
我无法弄清楚为什么没有输出这个自定义单元格.
我在故事板中设置了自定义单元格(没有笔尖).我有一个文本字段和2个标签,当我尝试在自定义单元格类中访问它们时为nil.我几乎可以肯定我已经把所有东西都搞定了,但仍然没有.
我已经在故事板中选择了我的表格单元格并将自定义类设置为TimesheetTableViewCell
我也控制了单击该表并将数据源和委托设置为TimesheetViewController
我的自定义单元类:
import UIKit
class TimesheetTableViewCell: UITableViewCell {
@IBOutlet var duration: UITextField!
@IBOutlet var taskName: UILabel!
@IBOutlet var taskNotes: UILabel!
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init?(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
println("Cell's initialised")// I see this
println(reuseIdentifier)// prints TimesheetCell
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
func setCell(duration: String, taskName: String, taskNotes: String){
println("setCell called")
self.duration?.text = duration
self.taskName?.text = taskName
self.taskNotes?.text = …
Run Code Online (Sandbox Code Playgroud) 将json-ld添加到 vue 应用程序的正确方法是什么\xe2\x80\x99 ?
\n\n我\xe2\x80\x99添加了一些结构化数据,但Google结构化数据测试工具未检测到我的网址上的数据。但是,如果我查看 url 的来源并将其粘贴到测试工具中,它会检测到我的数据。缺少什么?
\n尝试从 vue 中访问电子并抛出 TypeError。
TypeError: fs.existsSync is not a function
at getElectronPath (index.js?bdb9:7)
at Object.eval (index.js?bdb9:18)
at eval (index.js:20)
Run Code Online (Sandbox Code Playgroud)
搜索谷歌并没有太大帮助。我发现一篇帖子建议将以下内容添加到 vue.config.js 可以解决问题。那对我不起作用。
module.exports = {
pluginOptions: {
electronBuilder: {
nodeIntegration: true
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用以下
包.json:
{
"name": "test",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"dependencies": {
"axios": "^0.19.2",
"core-js": …
Run Code Online (Sandbox Code Playgroud) 我有一个嵌入在视图控制器中的容器中的表视图控制器.
在视图和表视图控制器中,prepareForSegue方法我把NSLog(@"控制器的名称")我看到了视图控制器的日志而不是表视图控制器.我不应该也看到我的表视图的prepareForSegue的nslog?
objective-c uitableview uiviewcontroller ios uistoryboardsegue
我在使用UIImageJPEGRepresentation时收到内存警告,有什么方法可以避免这种情况吗?它不会崩溃应用程序,但我想尽可能避免它.它间歇性地不运行[[UIApplication sharedApplication] openURL:url];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
NSData *imageToUpload = UIImageJPEGRepresentation(image, 1.0);
// code that sends the image to a web service (omitted)
// on success from the service
// this sometime does not get run, I assume it has to do with the memory warning?
[[UIApplication sharedApplication] openURL:url];
}
Run Code Online (Sandbox Code Playgroud) 我对这句话做错了什么?currentRow是一个NSIndexPath
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row && currentRow?.row == 5 {
return 300
}
return 70
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
类型'Int'不符合协议'BooleanType'
使用预设组件值创建UIColor
Run Code Online (Sandbox Code Playgroud)+ blackColor
返回一个颜色对象,其灰度值为0.0且其alpha值为1.0.
有没有一种方法来检索颜色对象"灰度值"?
为什么我的 docker-compose 目标是 dockerfile 中的 prod 阶段,同时也运行 dev 目标?
命令:
docker-compose -f 'docker-compose-prod.yml' up --build
我专门瞄准prod
但docker-compose-prod.yml
目标dev
也在运行。
Step 4/18 : FROM base as dev
---> 89ae35cdccf6
Step 5/18 : RUN npm install
---> Using cache
---> 8d6693e78ce0
Step 6/18 : COPY . .
---> 93518e386a6e
Step 7/18 : RUN npm run build
---> Running in 44199ae5793a
Run Code Online (Sandbox Code Playgroud)
docker文件:
# base
FROM node:lts-alpine as base
WORKDIR /usr/src/app
COPY package*.json ./
# dev
FROM base as dev
RUN …
Run Code Online (Sandbox Code Playgroud) 我犯了升级xcode的错误,这很痛苦。
我尽力满足苹果的要求“使用当前的公共(GM)版本的Xcode重建我的应用并重新提交”。
一些细节Xcode 7.0.1-无效的Swift支持-cocoapods如何修复?
据我所知,我正在使用当前的大众汽车(GM)。我使用的是7.0.1版(7A1001),如果有人不是当前的公众人士(GM),请告诉我。
我在这里尝试了几乎所有“解决方案”,但错误仍然存在。
现在,我要重新安装xcode作为最后的了解。当然,这个过程是神秘的,您如何进行“重新安装” xcode?我听说xcode有一个“巨大的足迹”,所以这不是浪费应用程序的问题,对吗?
我无法理解为什么我无法切换选定的表格行.我在didSelectRowAt中成功设置了accessoryType.但我似乎无法在didDeselectRowAt中将accessoryType设置为none.
我的数据:
serviceItems = ["Heater", "Air Conditioner", "Boiler", "Heat Pump"]
Run Code Online (Sandbox Code Playgroud)
这是我的tableview覆盖:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.accessoryType = .checkmark
let serviceItem = serviceItems[indexPath.row] as! String
cell.textLabel?.text = serviceItem
}
// does not remove checkmark
// does not change textLabel to "test"
// DOES print "DESELECTING" (so I know its getting called)
override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.accessoryType = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将一些代码移植到swift.到目前为止,它做起来相当简单,但我仍然坚持使用keysSortedByValueUsingComparator.任何人都可以帮我把我的objc代码翻译成swift吗?
我特意不明白如何翻译这一点:
keysSortedByValueUsingComparator:^(id obj1,id obj2){}
我理解的大括号之间的东西
NSArray* matches = [startingExposureLookup keysSortedByValueUsingComparator:^(id obj1, id obj2) {
NSNumber* x = [NSNumber numberWithFloat:fabs([obj1 floatValue] - totalExposureTimeInSecondsFloat)];
NSNumber* y = [NSNumber numberWithFloat:fabs([obj2 floatValue] - totalExposureTimeInSecondsFloat)];
return [x compare:y];
}];
Run Code Online (Sandbox Code Playgroud) 我从userDefaults获取的值可能是nil或者可能是NSDate,所以我想检查,因为我需要在该日期采取行动.我该如何正确地进行检查?
let timeAtQuit: NSDate = (userDefaults.objectForKey("timeAtQuit") as NSDate)
if(timeAtQuit){ Type 'NSDate' does not conform to protocol 'BooleanType'
if(timeAtQuit != nil){ // 'NSDate' is not convertible to 'UInt8'
another attempt:
var timeAtQuit:NSDate? = (userDefaults.objectForKey("timeAtQuit") as NSDate)
if(timeAtQuit != nil){
let timeSinceQuit:Double = timeAtQuit.timeIntervalSinceNow // 'NSDate?' does not have a member named 'timeIntervalSinceNow'
}
Run Code Online (Sandbox Code Playgroud) ios ×7
swift ×6
objective-c ×3
uitableview ×2
vue.js ×2
custom-cell ×1
docker ×1
electron ×1
ios7 ×1
javascript ×1
json-ld ×1
memory-leaks ×1
nsdate ×1
nsdictionary ×1
swift2 ×1
swift3 ×1
testflight ×1
uicolor ×1
uipickerview ×1
xcode ×1