我试图获取index所选项目TableView并在此之后开始一些活动.不幸的是,我发现的大多数解决方案都是客观的,或者不起作用.
方法func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)不打印cell标签..
有人可以帮帮我吗?
import UIKit
import ResearchKit
class TaskListViewController: UIViewController, UITableViewDataSource {
let tasks=[("Short walk"),
("Audiometry"),
("Finger tapping"),
("Reaction time"),
("Spatial span memory")
]
//how many sections are in your table
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
//return int how many rows
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tasks.count
}
//what are the contents
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) … 我将主应用程序中的数据保存在存储在 userDomainMask 某处的文件中。
NSKeyedArchiver.archiveRootObject(stops, toFile: BusStop.ArchiveURL.path)
Run Code Online (Sandbox Code Playgroud)
这是在我的 BusStop 类文件中
static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
static let ArchiveURL = DocumentsDirectory.appendingPathComponent("stops")
Run Code Online (Sandbox Code Playgroud)
现在我想从我的 Today Extension 和它返回的空集 [] 中读取这些数据,所以我知道问题出在哪里。我需要将此数据保存在我的扩展程序和应用程序所属的共享应用程序组中。
如何保存数据并从中读取数据?
编辑:
我解决了我的问题!
使用此解决方案:
static let ArchiveURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.asd.asd.asd")!
.appendingPathComponent("mypath")
Run Code Online (Sandbox Code Playgroud)
每次对已保存的数据进行操作或保存新内容时,请使用以下解决方案:
干杯!
我有一个带有订单列表的csv文件,如下所示:
CUSTOMER_CODE,CUSTOMER_NAME,NAME,PRODUCT
1044, C1, Name1, Arduino,
1044, C1, Name1, ESP8266,
1048, C2, Name1, Arduino Uno,
1042, C3, Name1, ESP32,
1049, C4, Name1, Arduino Mega,
1042, C3, Name1, Nexus 4,
Run Code Online (Sandbox Code Playgroud)
现在我只想提取客户代码列表
[1042, 1044 ,1048 ,1049]
不
[1042, 1044 ,1044,1044,1044,1044,1044,1044,1048,1048,1048,1048,1048,1048,1048,1049 etc.]
#!/usr/bin/python
import MySQLdb, csv
CUSTOMER_CODES = []
with open('Customers.csv','r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if len(CUSTOMER_CODES) == 0:
#adding 1st value
CUSTOMER_CODES.append(int(row['CUSTOMER_CODE']))
for i in range(0,len(CUSTOMER_CODES)):
#check each value of table
print CUSTOMER_CODES
if CUSTOMER_CODES[i] == int(row['CUSTOMER_CODE']): …Run Code Online (Sandbox Code Playgroud) 我试图找到最佳解决方案来对我的数据库中的所有 Machine 对象进行排序并找到最后使用的 deviceSerialNo。
deviceSerialNo 是一个字符字段,具有如下结构:AB12-12344。
我的任务是通过 deviceSerialNo 字段的子字符串(deviceSerialNo 中“-”之后的所有内容)对所有 Machine 对象进行排序。我目前的解决方案是这样的
last = Machine.objects.all().order_by('-deviceSerialNo').first().deviceSerialNo
或者
last2 = Machine.objects.all().order_by('-deviceSerialNo').annotate(search_index=StrIndex('deviceSerialNo', V('-'))).first().deviceSerialNo
有人可以按照我上面提到的方式帮我排序吗?