0

I create a UITableViewController's subclass:

class BaseTableViewController: UITableViewController {

    var negozio : negozioAttivo?

}

Then , I created a BaseTableViewController's subclass

class offerteTableViewController: BaseTableViewController{

    private var offerte : Array<offerta>?
    private var cellIdentificatior : String = "Cell"

    override func viewDidLoad() {
        super.viewDidLoad()


    }
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return (self.offerte)!.count
    }
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

        return CGFloat(220)
    }
    override func viewWillAppear(animated: Bool) {

        self.offerte = Database.getOfferteNegozio(1)
    }
    override var description: String {
        return "Offerte"
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        var cell = tableView.dequeueReusableCellWithIdentifier(self.cellIdentificatior) as? TableCellSex


        if (cell == nil ) {

            var shop : negozioAttivo = self.negozio!
            var id : Int = shop.id
            var fotoPrinci : foto = shop.getPhoto(1)
            var image : UIImage = fotoPrinci.downloadImage()!

            cell =  TableCellSex(text: shop.nome, image: image, id: self.cellIdentificatior, style: UITableViewCellStyle.Default,width: 150, height: 250 , star: Int(3) , distanza : "1km" , showHeart: true , male: shop.uomo == false , female: shop.donna == false)

        }

        return cell!
}
}

Then I created a UITableView in StoryBoard and I give it the type of offerteTableViewController , but when I execute it I get this: the first cell is too above and goes off the screen ( in fact the picture is not seen completely)

gino gino
  • 249
  • 1
  • 4
  • 8

2 Answers2

0

If your navigationVC has a translucent navigation bar and you want to tableview to be visible under the navigation bar when you scroll, then in your Storyboard, check the "Under Top Bars" which means you want the VC to scroll underneath the navigation bar and also check "Adjust Scroll View Inset" so that the scroll start below the navigation bar.

enter image description here

More detailed explanation can be found here: Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

Note that this only works if your tableViewController is the rootView of your navigationVC.

In the special case of navVC -> PageVC ->TableVC add this to your tableview viewWillAppear

  self.tableView.contentInset = UIEdgeInsetsMake(CGRectGetMaxY(self.navigationController.navigationBar.frame), 0,0,0);
    if(self.tableView.contentOffset.y == 0 ){
        self.tableView.contentOffset = CGPointMake(0, -CGRectGetMaxY(self.navigationController.navigationBar.frame));
    }
Community
  • 1
  • 1
null
  • 1,178
  • 8
  • 15
  • the general situation is this : this offerteTableViewController is within pageviewController and it has a navigation controller – gino gino Dec 10 '15 at 01:42
  • Try unchecking both option, also make sure you are not overriding these setting by using these functions: setEdgesForExtendedLayout, setAutomaticallyAdjustsScrollViewInsets – null Dec 10 '15 at 01:45
  • I have to set false those functions ? – gino gino Dec 10 '15 at 01:47
  • yes now it works , thanks , but can you explain me why this happens? – gino gino Dec 10 '15 at 01:50
  • the EdgeLayout and AdjustsScrollViewInsets are both only relevant if your navigationView has a translucent navigation bar, which is a cool effect introduced in ios7 that allows content to be visible underneath the navigation bar. If you don't use this effect then you can set the navigationBar translucent to NO and set these two options to NO and then everything will start below the navigation, like good old ios6 style. If you do want this effect but you are using pageVC as your navVC's rootView then you need that little hack i added. – null Dec 10 '15 at 02:00
  • if this answer solved your problem please accept it. thank you – null Dec 10 '15 at 02:03
0

This sounds like your navbar is overlapping with your tableview. You could set the contentInsets of your tableView so that it starts offset from the top

self.tableView.contentInset = UIEdgeInsetsMake(64,0,0,0);

or try setting your navigation bar navigationBar.translucent = NO; if it is set to yes.

Joseph Afework
  • 269
  • 1
  • 4