How to use SkeltonView using RxSwift, RxCocoa - swift

I wanna use SkeltonView in my app. But, it was described that we need to confirm to SkeltonTableViewDataSource to use it in README.
Is there any one who knows to use SkeltonView like tableView.rx.items.
If you want to show the skeleton in a UITableView, you need to conform to SkeletonTableViewDataSource protocol.
public protocol SkeletonTableViewDataSource: UITableViewDataSource {
func numSections(in collectionSkeletonView: UITableView) -> Int // Default: 1
func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int
func collectionSkeletonView(_ skeletonView: UITableView, cellIdentifierForRowAt indexPath: IndexPath) -> ReusableCellIdentifier
func collectionSkeletonView(_ skeletonView: UITableView, skeletonCellForRowAt indexPath: IndexPath) -> UITableViewCell? // Default: nil
func collectionSkeletonView(_ skeletonView: UITableView, prepareCellForSkeleton cell: UITableViewCell, at indexPath: IndexPath)
}

Related

tableview header and prototype cell showing wrong

Is there are reason why there are height differences between what is shown and what has been set as a height? also there is a space between header and prototype cell which I cannot get rid of.
extension FirstTabThirdView: UITableViewDataSource , UITableViewDelegate {
func tableView (_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = headerView
return view
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellOne", for: indexPath)
cell.textLabel?.text = "hello"
return cell
}
}

type 'ThirdViewController' does not conform to protocol UITableViewDataSource

I have started my first app, and I want the app to have a view that works as a to-do list, however, I'm getting type 'ThirdViewController' does not conform to protocol UITableViewDataSource as an error in my code. I already looked at a similar thread but found no solution there
import UIKit
class ThirdViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
{
var list = ["Math Homework", "English Project", "Bio Quiz"]
#IBOutlet weak var myTableView: UITableView!
override func viewDidLoad()
{
super.viewDidLoad()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return list.count
}
public func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell
{
let cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "cell")
cell.textLabel?.text = list[indexPath.row]
return cell
}
}
As specified in the Apple Developer documentation, you need the following methods:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
You instead used these:
public func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell
public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
Remove public from both methods and it should work. Also, add _ before tableView:.
Reference:
https://developer.apple.com/reference/uikit/uitableviewdatasource
EDIT:
The methods that I described are for Swift 3. In case you are using Swift 2.3, these should be your methods:
func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
Almost the same that you used in the first place, but without public.
Implement the required protocol methods for UITableViewDataSource and UITableViewDelegate.
you are missing;
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

Swift 3 UITableView sections showing after the list

I'm trying to create a list of products using swift 3 UITableViewController, but the sections is showing after the list of the products. There must be something I'm missing, couldn't find anywhere
Here is a simplified code
let data = [["0,0", "0,1", "0,2"], ["1,0", "1,1", "1,2"], ["2,0", "2,1", "2,2"], ["3,0", "3,1", "3,2"]]
override func numberOfSections(in tableView: UITableView) -> Int {
return data.count//productCategoriesSections.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data[section].count//productCategories[section].count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "defaultCategoryCell", for: indexPath) as! CategoryDefaultTableViewCell
cell.titleTextView.text = data[indexPath.section][indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return "Section \(section)"
}
screenshot
It is because you are using wrong callback.
Use override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? instead of override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?.
The former will place the text as a header above the section. The latter places it at the bottom.

Can't override UITableViewDataSource and UITableViewDelegate

extension FormViewController : UITableViewDelegate {
public func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath?
public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
public func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
public func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
public func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
public func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
}
extension FormViewController : UITableViewDataSource {
public func numberOfSectionsInTableView(tableView: UITableView) -> Int
public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?
public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String?
}
class NotifiableFormViewController: FormViewController
Why can't I implement and override the DataSource and TableViewDelegate? Error:"Method does not override any of it's superclass method"
class FriendsTableViewController: NotifiableFormViewController{
override func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
override func tableView(tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath)
cell.textLabel?.text = "Section \(indexPath.section) Row \(indexPath.row)"
return cell
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Section \(section)"
}
}
more simply, remove the word override because you're not overriding the method, you are implementing it
UITableViewDataSource and UITableViewDelegateare just protocol
If you want override it, you implement above functions in NotifiableFormViewController
then override in your FriendsTableViewController
but if not implement in your super class, then you can't override it (nothing override implemented delegate or datasource function)
By definition, extensions can only add functionality to existing classes. It can not change, that includes overriding, the existing implementation.

what do tableview functions (CellForRowAtIndexPath and numberOfRowsInSection) do?

I was viewing some videos on app development with swift, they used these functions but they did not explain about them much. What do they do exactly?
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
This function is used in the table view data source to specify how many table view cells you want in the given section. To get this function call (and the other calls), you need to set tableView.dataSource = self. Then you can implement this method to set a number of cells in the section.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
Use this function to get a UITableViewCell and customize the cell for when it is shown in the table. This method will also be called because of the data source property we set. Implement this and return a cell. Here is an example:
// This code is off the top of my head, sorry if the syntax or method names are off
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellForReuseIdentifier("ReuseIdentifier", indexPath: indexPath)
cell.textLabel?.text = "A title for the cell"
return cell
}