Search code examples
iosiphonexcodexcode6xcode-storyboard

add constraint to view in Xcode 6


I wanted to add an image but stack overflow doesn't allow me to upload any photo because of the reputation issue. I leave a link for it. https://www.evernote.com/l/AbqeZCbSUD1GWbDIiigHjtpkOmncUDZglQI

anyway,

I have an iOS project with Xcode 6.

I made a view controller and added a table view.

view controller
- Top Layout Guide
- Bottom Layout Guide
- View
+- Table View

After that,

I added a view and a table view cell

view controller
- Top Layout Guide
- Bottom Layout Guide
- View
+- Table View
++- View
++- Table View Cell

My problem is that the height of View of Table View is about 30 on Story board. But while running simulator, Table View Cell is almost at the bottom.

But I cannot add constraint to set the height of View of Table View.

Thank you in advance!


Solution

  • In your case, firstly, you should move the second view out of the Table View. The right layout should be like:

    view controller
    - Top Layout Guide
    - Bottom Layout Guide
    - View
    +- View
    +- Table View
    ++- Table View Cell
    

    Then, you should set some proper constraints between the second View(The User Name in your case) and Table View. If you still not familiar with Auto layout and don't know how to work with constraints, I strongly suggest you to take a look at this brilliant article which will solve most of the puzzles :

    http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

    Finally, you can adjust the height of your table view cell further by using this method:

    -(CGFloat)tableView:(UITableView *)tableView 
    heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
    }