Home > DeveloperSection > Forums > How to set Activity Indicator in UITableView in Objective-C?
JAMES Williams
JAMES Williams

Total Post:7

Posted on    April-23-2016 2:15 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 631  View(s)
Rate this:
I want to display activity indicator for the initial load time for each collection view cell. So I tried to place it in the table view delegate method cellForItemAtIndexPath: and created 25 pixels above the cell for some reason.
Below is my code:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("AACollectionViewCell", forIndexPath: indexPath) as! AACollectionViewCell
    let activityView = UIActivityIndicatorView (activityIndicatorStyle: .Blue)
    activityView.center = cell.myImage.center

    activityView.center = cell.contentView.center

    return cell
Now, Please tell me the proper way to handle the activity indicator or what the wrong in my code..!
Thank you.

Tarun Kumar

Total Post:214

Posted on    April-25-2016 1:41 AM

You can use cell.contentView.center which gives us the frame of contentView from its superView' coordinate system.
User like the below example:
activityView.center = CGPointMake(cell.contentView.frame.size.width / 2,
                                       cell.contentView.frame.size.height / 2)
I hope it will be helpful for you.

Modified On Apr-25-2016 01:41:23 AM

Don't want to miss updates? Please click the below button!

Follow MindStick