Why interface builder not let me to add uiview to uitableview? - ios

I have a table view. I want to add some features so when user click on a cell another view opens and show details about that cell. I am trying to follow this part of video to add uiview:
youtube tutorial
But when I drag and drop it myself, it returns back and is not adding to tableview. Here is my storyboard.

I see your attached image and as per that i think you have use UITableViewController which has mainview is UITableView.
But the video you are trying to follow , in that they have take a UIViewController which has mainview is "UIView". in that they have have drag an drop UITableview. And then they have added a another UIView in "mainview which is "UIVIEW" " not UITableview.
If you want to learn how to sue UITableview in UIViewController, there here is the tutorial link :
http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/ 
If you follow this steps then also you will be able to create the same tableview which you have currently developed. And then you try to add a view to MAINVIEW. it will allow you to add it.

You shouldn't be adding UIViews to UITableView. The content that UITableView displays should be cells returned by the relevant methods of UITableViewDataSource and UITableViewDelegate.
Specifically for your case, in the YouTube tutorial you referred to, the UIView is dragged on top on the UITableView, and not inside the UITableView. So the parent view isn't the table view, is the View Controller's main view.
Try that and continue with the tutorial to get to the table view's content - the cells. Good Luck!

Related

UITableView inside a UITableView?

Generally:
Is it OK to add a UITableView as a subview of another UITableView? Or, should I create a UIView and add each UITableView to it?
Specifically:
For a ComposeTableViewController with a typeahead, like in the iPhone's native Mail app, which approach would you recommend and why?
Note: I prefer to construct things 100% programmatically (no Interface Builder).
Subclass UITableViewController.
Then, to show the typeahead results, create and add a resultsTableView as a subview of self.tableView positioned directly underneath the the cell (of self.tableView) with the typeahead text field.
The nice thing about this approach is that resultsTableView scrolls with self.tableView automatically.
But, is it OK to add a UITableView as a subview of another UITableView?
Subclass UIViewController.
Create and add tableView (custom property) as a subview of self.view.
Create and add resultsTableView also as a subview of self.view.
The annoying thing about this approach is that I have to reposition resultsTableView manually anytime self.tableView scrolls.
I think I'd prefer approach 1, but adding a UITableView as a subview of another UITableView just seems smelly to me.
TableViews cannot have subviews. You can try adding a tableview as the view of a TableViewCell, but then you have to ask yourself how it would scroll, if you tried scrolling in the subtableview would it scroll the child tableview or the parent tableview? It is much easier to present multiple tableviews within a view. This can be done easily by setting your custom viewcontroller as the datasource of both tableviews contained within its view and then comparing the tableview pointer that is sent as a parameter of the datasource method to the two tableview pointers that are IVars of your custom view controller.
Hold stuff like this in a container. Create a container view controller which only does typeahead. This container view controller will hold your main table view controller (and its table view) and it will hold the typeahead view controller (and its view).
It will keep the logic needed for the typeahead out of your main table view and as a bonus you might end up with a reusable typeahead container which could be applied to other views.
Yes it is good to go for adding UITableView in as a cell of another UITableView.
I had one issue and posted a question
Multiple Views as subviews
And requirement was like a group of controls with list of other controls. I thought that time that it will be messy if i'm going to add UITableView as a cell of UITableView.
What i found that... Boy !! it's how iOS meant to be. There is no any lag while doing this.
Tested for below functionalities:
Scrolls like a charm
Separate delegates called for each
Reordering of both UITableView cell
Swipe and remove cell
Runtime datasource update for both UITableView and reload both at the same time.
There is no any reason not to add subview UITableView.
You can do it but it is against the principle of MVC. You will be setting the delegate of a view to another view which is wrong.

Implementing A Mail app-like User Interface

I am trying to implement a user interface that is similar to the iPhone's Mail app.
The main screen displays a table. From the table the user can select a cell, at which point the next screen is launched. At the bottom, there is a bar showing a short text and an icon.
The second screen displays the details of the cell. It will also be a table display. The bottom bar shows icons associated to this screen.
What kind of layouts do I use to implement this in Xcode?
1. Do I use a View controller, add a View and embed a TableView and a Toolbar inside that view?
2. Do I use a Table View Controller and add a Table View inside it and use the bottom tool bar that comes with the table view?
In the Table View Programming Guide for iOS, under 'Recommendations for Creating and Configuring Table Views,' it says 'Use an instance of a subclass of UITableViewController to create and manage a table view.' When I use this, the bottom bar can only be fixed or disappear when going back and forth between two screens via segue. That makes me wonder whether I should just use a View controller which is against the recommendation.
Use a UIViewController
Why?
If you are going to display more than a tableView then it is recommended to use a UIViewController for the storyboard.
UIViewController are much more flexible. I guess your confusion comes from the following documentation line:
Use an instance of a subclass of UITableViewController to create and
manage a table view
This does not mean you must to drag and drop a UITableViewController on the storyboard. It means your class need to inherit from UITableViewController or at least implement the deleguate and datasource methods.
You would use UITableViewController only and only if you need to display a tableView.

Floating button over UItableview using storyboards

I have made a table view using prototype cells on tableviewcontroller from storyboards.
I want a floating button over that uitableview. (button won't scroll with the tableview).
While searching for a solution..I found out that it is possible by adding button to the superview (in that case Uiviewcontroller subclasses Uitableview).
Can any one tell me how to do that using storyboards??
I think best thing you have to do is to create a UIViewController and add it a UITableView. Then you can add also the UIButton you want to the view controller's view. Don't forget to set the view controller to be the delegate and data source for your table view, and to add <UITableViewDataSource,UITableViewDelegate> to your view controller interface.
If you must do it using Storyboards and not in code, then you need to use a UIViewController and not a UITableViewController.
Add the UITableView and make it full screen - link up its Delegate and DataSource to the UIViewController and adhere to the two protocols in the .h file of your UIViewController.
When adding the button, drag it into the view hierarchy in the "Document Outline" sidebar, and not by dragging it onto the UITableView. Be careful if you're ever dragging the button around the view because if you drag and drop it on top of the UITableView then it will become a subview of the UITableView. If you want to move it around you'll need to select it and then use the arrow keys.
Anyway, apart from that it should all be very easy - add your constraints to keep it in the right place and you should be able to use the button as normal.

UITableViewController does not automatically resizes and repositions its table view when there is in-line editing of text fields

UPDATE (SOLVED ALREADY) :)
I tried to recreate my scene from scratch. And I found out that if the Class of the table view controller is "UITableViewController", the repositioning of view when keyboard appears happens properly. But when I set the Class of the table view controller to my custom class, the repositioning doesn't happen. Why is this so? Given that my custom class is a subclass of UITableViewController and nowhere in my implementation did I implement any data source and data delegate since I am using static cells?
I forgot to add the delegate in my interface declaration. Now it's working already.
#interface CustomClass : UITableViewController <UITableViewDelegate>
I have a UITableViewController where the tableview content is static cells and style is plain. I added 7 table view cells. In each cell, I added a text field.
When I click on a table view cell, the keyboard shows but the table view did not reposition; thus hiding the table view cell that I selected.
I have solved this before but I was using a view controller then which I embedded inside a scrollview. But seeing from documentation, UITableViewController, which has a scrollview by default, is supposed to automatically resize and reposition it's table view.
I am working on XCode 5 and using iOS 7 latest version.
You can change the offset (y) of the tableView whenever textField's action is didBeginEditing.
If you need any more help let me know ;D
It should automatically change its size, but not necessarily adjust its position/offset.
Are you sure the table view still covers the entire screen, even below the keyboard?
You can check this by scrolling and looking at the scrollbars.
If you want to adjust the content offset, do so in the callback when the user begins editing the text field.
Eliminate the code that sets the content offset of the table view.
The table cell for text field with the first responder status should automatically scroll above the keyboard. You shouldn't have to write a lick of code for this.
If you are using static cells, make sure that your table view controller does not implement the table view data source methods. Also, the view controller that you dragged onto the IB canvas must be a UITableViewController; it can't be a UIViewController that contains a UITableView dragged from the objects library.
After thorough checking, I realised, my custom class only subclass UITableViewController without adding the delegate :(
below solves the problem... at last! :)
#interface CustomClass : UITableViewController <UITableViewDelegate>

UIButton inside a UIScrollView

I would like to use a scroll view inside my app.I will explain the situation:
Mine is a recipe app.I would like to show all the recipe images inside a scroll view and when i click an image inside the scroll view ,the corresponding ingredients and preparations has to be shown .I saw many tutorials using image view inside the uiscrollview,thought of replacing image view with button.But all those tutorials are so complicated .Can any one refer me a simple example.
This my apps seccond page.when i click a particular recipe in first page its image and ingredients and preparation is shown.But i would like to show all the images in uiscrollview,and when i click a particular image,corresponding ingredients and preparations has to be shown
From my point of view I think that if you would use a UITableView or a UICollectionView (or the corespondent controllers: UITableViewController and UICollectionViewController) you would achieve grater results than trying to add buttons with images inside a scroll view.
UITableView Tutorial and UICollectionView Tutorial
Also you can go and watch the Apple's WWDC videos
I hope this is helpful for you,
Cheeers
Place UIscrollview In View Xib, then add UIButtons Inside UIScrollview , set buttons actions by hooking action type touch up inside in button pressed add subview on UIView and Show details of Recipe.[self.view addSubView:RecipeDetailView]; here recipe detail view subview where you load reciepe info on button pressed.

Resources