Swift 今日扩展-无法加载
我今天试图将数据加载到extension中的一个表中-数据显示在1开始,然后显示消息“无法加载” 控制台不显示任何数据-可能是什么问题 以下是我在viewDidLoad中的代码:Swift 今日扩展-无法加载,swift,today-extension,Swift,Today Extension,我今天试图将数据加载到extension中的一个表中-数据显示在1开始,然后显示消息“无法加载” 控制台不显示任何数据-可能是什么问题 以下是我在viewDidLoad中的代码: override func viewDidLoad() { super.viewDidLoad() self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded loader.startAnim
override func viewDidLoad() {
super.viewDidLoad()
self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded
loader.startAnimating()
loader.hidesWhenStopped = true
statusLabel.isHidden = true
tableView.delegate = self
tableView.dataSource = self
tableView.tableHeaderView = nil
tableView.isHidden = true
tableView.register(UINib(nibName: "LatestCell", bundle: nil), forCellReuseIdentifier: "latestCell")
if(checkDownloadable())
{
//Download OFFLINE
let realm = try! Realm()
let postsRealm = realm.objects(PostRealm.self)
var newPosts = [Post]()
var items: Int {
if(postsRealm.count > 5)
{
return 5
}else{
return postsRealm.count
}
}
for i in 0..<items {
let postRealm = postsRealm[i]
let postStandard = Post.init(id: postRealm.id, title: postRealm.title, date: postRealm.date, url: postRealm.url, content: postRealm.content, image: postRealm.image, authorName: postRealm.authorName, authorImage: postRealm.authorImage)
newPosts.append(postStandard)
}
self.posts = newPosts
self.loader.stopAnimating()
if(newPosts.count == 0)
{
self.statusLabel.isHidden = false
self.statusLabel.text = "Brak postów"
self.tableView.isHidden = true
}else{
self.statusLabel.isHidden = true
self.tableView.isHidden = false
}
self.tableView.reloadData()
}else{
//DOWNLOAD ONLINE
API.postsWidget(){ post in
self.posts = post ?? [Post]()
self.loader.stopAnimating()
if(post?.count == 0)
{
self.statusLabel.isHidden = false
self.statusLabel.text = "Brak postów"
self.tableView.isHidden = true
}else{
self.statusLabel.isHidden = true
self.tableView.isHidden = false
}
for p in self.posts {
self.addNewPost(post: p)
}
self.tableView.reloadData()
}
}
}
override func viewDidLoad(){
super.viewDidLoad()
self.extensionContext?.widgetLargestAvailableDisplayMode=.extensed
loader.startAnimating()
loader.hidesWhenStopped=true
statusLabel.ishiden=true
tableView.delegate=self
tableView.dataSource=self
tableView.tableHeaderView=nil
tableView.ishiden=true
tableView.register(UINib(nibName:“LatestCell”,bundle:nil),强制重用标识符:“LatestCell”)
if(checkDownloadable())
{
//离线下载
让realm=try!realm()
让postsRealm=realm.objects(postream.self)
var newPosts=[Post]()
变量项:Int{
如果(postsrelam.count>5)
{
返回5
}否则{
返回postsrelm.count
}
}
因为我在0。。