unable to print response from api in collectionView
you just need to reload you collectionView - try this in your do statement
DispatchQueue.main.async() {
self.collectionView.reloadData()
}
Collection View Not Showing Data
Try instead of
nc.post(name: Notification.Name("didFinishParsing"), object: nil)
send
nc.post(name: Notification.Name("didFinishParsing"), object: news)
Then instead of
guard let news = notification.object as? Article else { return}
write
guard let news = notification.object as? News else { return}
print("News == \(news)")
self.news = news.articles
Not able to append the value and display in collection view
You just need to call collectionView.reloadData()
after you have loaded all of the values in getallLoans
.
When you make the API call, this is an asynchronous task that will take a little time to complete. Your collection view will have already loaded it's data source so you need to inform it that the data has changed. It will then call the CollectionViewDataSource delegate methods again and refresh the view based on the updated data.
for (_, val) in json {
print(val.rawString()) // displaying the correct each items names
self.mobkam.append(val.rawString()!)
}
collectionView.reloadData()
Unable to show all JSON response values in Collectionview(ERROR: Index out of range) in Swift
First of all consolidate the naming of the variables to make clearer what is a single object and what is an array.
- Replace
bidAttatchment
withattachments
(plural form) - Replace
Get_attachments
withAttachment
(singular form) - Declare the array as non-optional empty array. The benefit is you get rid of all the question marks
Then in numberOfItemsInSection
just return the number of items in attachments
. Your data source doesn't contain sections so the section
parameter is irrelevant.
class ViewProposalTableVIewCell: UITableViewCell, UICollectionViewDelegate,UICollectionViewDataSource {
@IBOutlet weak var attetchmentsCollectionview: UICollectionView!
public var attachments = Array<Attachment>()
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return attachments.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "BidAttatchmentCollectionViewCell", for: indexPath) as! BidAttatchmentCollectionViewCell
let attatchBid = attachments[indexPath.item]
cell.attatchmentLbl.text = attatchBid.filename
return cell
}
Why i am not able to delete one more CollectionVIew Cell with JSON parameter in swift?
You are storing picture with same key in user defaults, which is wrong. it will only store last item of the loop.
You should add picID in your model inside postServiceCall method like this
self.arrImageItems.append(ImageItemModel(title: self.titleTextfield.text, imgTitle: self.imageProfile, picID: picId))
and then in deleteService method you need to get picID like this
let picId = UserDefaults.standard.string(forKey: "pic_id")//Replace this with this one
let picId = arrImageItems[sender.tag]. picID
Now everything will work fine.
Related Topics
Swift Swipe Navigation Table Views
Viewcontroller.Type Does Not Have a Member Names 'Answerone' - Swift
Rxswift - Generic Parameter 'Self' Could Not Be Inferred
Error When Trying to Save a Captured Image in Swift
My Reachability Notifier Is Only Able to Be Called Once
Multiple File Upload with Array of Parameters Using Alamofire
Table View Controller Duplicate Itself in iOS Swift
Exc_Breakpoint (Sigtrap) on Production Version Only
How to Change a View from Portrait Mode to Landscape Mode and Lock It
Array Element Checking in Swift
Firebase Checking for Null Value (Swift)
Uialertcontroller Title and Message Not Appearing
Programmatically Obtaining the Imei or Udid of an iOS Device
Update Storyboard Constraint Using Code
Swift - Set Delegate for Singleton
Dynamically Passing Closure with Keypaths to a Sorting Function