-2

I have a problem with how the last cell appears in the table as well as loading more cells through the API

I would also like to add the Gray Activity Indicator At the bottom of the cells in the queue while loading the cells

Use Alamofire library Swift 5

iyas seyam
  • 55
  • 1
  • 9

2 Answers2

0

We can achieve this using the tableview delegate method

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

This delegate method is called before tableview uses cell to draw a row which allows us to customise the cell before being displayed. In this override method we get indexPath which can be used to check if the cell is the last one.

ayon.gupta
  • 178
  • 7
0

For Gray Activity Indicator At the bottom add a custom cell with a Activity indicator along with a label stating "fetching more..........." or else show like below

To Add Activity indicator in tableview

func showIndicator() {
    let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)

    spinner.startAnimating()
    tableView.backgroundView = spinner
}

To get last cells and load more data from api

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
         if yourArr.count-1 == indexPath.row{
            getMoreImages(page)
         }
 }

    func getMoreImages(page:Int){ 
       //hit api
       if api_success == true {
           if self.page == 0 {
              self.yourArr.removeAll()
           }
       self.yourArr.appendContentsOf(api_data)
       self.tableView.reloadData()
       self.page = self.page + 1
       }
    }
kannan
  • 354
  • 1
  • 7
  • how to set CountdownLabel pod in label I can't display the timer in the text You have implemented all the instructions on the website I want to put a timer for 24 hours only Have you seen web site pod in github https://github.com/suzuki-0000/CountdownLabel? This code did not work! :: – iyas seyam Aug 11 '19 at 17:53
  • let countdownLabel = CountdownLabel(frame: CGRect.zero, minutes: 60*60*60) override func viewDidLoad() { super.viewDidLoad() timer.text = countdownLabel.text countdownLabel.animationType = .Pixelate countdownLabel.start() } @IBOutlet weak var timer: UILabel! – iyas seyam Aug 11 '19 at 17:53
  • @iyas seyam - will you explain me this in detail i can't get you, if possible create a question feed with the code so that it will be easy to understand – kannan Aug 13 '19 at 09:13
  • @iyas seyam - upto this i believe the countdown label liberary you used is not working – kannan Aug 13 '19 at 09:14
  • Is there a countdown timer pod ? – iyas seyam Aug 13 '19 at 10:47
  • For countdown timer pod, You could choose based on your design needs and swift version from the below link, github.com/topics/countdown-timer?l=swift – kannan Aug 15 '19 at 16:26
  • Sorry for the delay you could refer the below link for simple countdown flow, https://stackoverflow.com/questions/29374553/how-can-i-make-a-countdown-with-nstimer – kannan Aug 15 '19 at 16:27