我正在使用documentPicker获取任何文档的url路径,然后上传到数据库.我选择文件(pdf,txt ..),上传工作但我想限制文件的大小.
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
self.file = url //url
self.path = String(describing: self.file!) // url to string
self.upload = true //set upload to true
self.attachBtn.setImage(UIImage(named: "attachFilled"), for: .normal)//set image
self.attachBtn.tintColor = UIColor.black //set color tint
sendbtn.tintColor = UIColor.white //
do
{
let fileDictionary = try FileManager.default.attributesOfItem(atPath: self.path!)
let fileSize = fileDictionary[FileAttributeKey.size]
print ("\(fileSize)")
}
catch{
print("Error: \(error)")
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误消息,此文件不存在,文档选择器保存文件以及如何获取其属性.
我试图根据标识符设置表格视图中每个单元格的高度。我不想使用 indexPath.row,因为我正在从包含每个单元格类型标志的数组中填充单元格,并且顺序是随机的。正好 3 种类型的细胞。
我使用了这段代码,但它导致了一个错误:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let cell = tableV.cellForRow(at: indexPath)
if(cell?.reuseIdentifier == "homeFeaturedR"){
return 200
}else{
return 360
}
}
Run Code Online (Sandbox Code Playgroud)
错误在这一行:
let cell = tableV.cellForRow(at: indexPath)
Run Code Online (Sandbox Code Playgroud)
谢谢你。
我每隔几分钟刷新一次我的UITable,如果有新数据,它们应该在表的开头添加而不是重新加载.
var j = 0
let n = store?.news?.count
while(j < n!){
self.news?.insert((store?.news?[j])!, at: j)
j = j + 1
}
Run Code Online (Sandbox Code Playgroud)
在第一个位置保存数据没问题.问题是我不能保持单元格位置在每次重新加载后向上移动(添加的记录数),我已经尝试了多个功能但显然它只适用于表格末尾添加的数据.
let contentOffset = self.tableV.contentOffset
self.tableV.reloadData()
self.tableV.contentOffset = contentOffset
Run Code Online (Sandbox Code Playgroud)
此外,我厌倦了保存单元格位置并添加输入数据的计数,但这种添加不起作用.有没有办法添加计数的输入数据的数量,让N对indexPath.row?
我正在尝试在应用处于活动状态时显示横幅通知.我使用了给定的方法但没有结果,横幅通知仅在应用关闭时出现:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print("Push notification received: \(userInfo)")
if application.applicationState == .active {
print("active")
let localNotification = UILocalNotification()
localNotification.userInfo = userInfo
localNotification.alertAction = "Test"
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.alertBody = "Notification test!!"
localNotification.fireDate = Date()
UIApplication.shared.scheduleLocalNotification(localNotification)
}
}
Run Code Online (Sandbox Code Playgroud)
它打印"活动"但通知未显示.我错过了任何一步吗?
谢谢.