i used the ib to create a uiimageview footer in the tableview, i want that the image will appear all the time while rolling and not just when rolling to the end of the table,
is there a way to d that?
Yes, but your view hierarchy will need to change.
You will need to make the view controller a subclass of UIViewController, and a delegate for UITableViewDelegate and UITableViewDataSource.
In this arrangement, you have a normal view controller, with a base view that remains static. You add a UITableView to that view, and depending on the size & placement you can have that base view showing at either top or bottom (or both).
Connect up your table-view to an outlet in the controller, set it's data source and delegate to the files-owner, and use the same delegate methods that a normal UITableViewController does.
One thing I've noticed is that a UITableViewController will automagically deselect any selected cell (either as the table disappears or reappears, I forget which). You will just have to manage that in:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
or in
- (void)viewWillAppear:(BOOL)animated.
No, the footer is part of the table itself. In fact, it is part of a section of the table. The footer only has meaning the in the context of the data above it so having a footer always visible would not make sense in the interface grammar.
Related
I have a custom view controller that has a view on the bottom half.
I would like to add a static UITableView on the top half.
So I dragged a UITableView on the view controller but apparently that is not allowed since static table views only are only embeddable in UIViewControllers.
I went to my code and made my controller extend UITableView but that doesn't fix the issue.
How do I add my static UITableView as a second view in my custom controller?
EDIT: Perhaps having a table view not taking up the whole screen is not very well supported in iOS storyboards. Maybe I will just use regular tables on a view since i just need 3 static rows.
You should be able to do something simple like this:
UITableViewController *tbv = [[UITableViewController alloc] initWithFrame:[CGRect whateverSize/Location]];
[self.view addSubview:tbv];
Be sure when doing this to also write needed delegate functions such as numberOfRowsInSection: , numberOfSections: , cellForRowAtIndexPath:, tableView:didSelectRowAtIndexPath:
Be sure to check out the UITableView Class Reference
I solved this issue by making my second view controller a simple UIViewController that implements the delegate and datasource, dragging a dynamic table on it and setting the rows and sections "statically" in code. Now I have my two views correctly cohabiting in a large view.
Using a dynamic, custom cell prototype that I design in, say, UITableViewController A (in Interface Builder/Storyboard), works really well with dequeuing the cell (through its identifier, cellA) and such in cellForRow... I use a custom class (UITableViewCell subclass, let's name it MyCustomCell) to link up the labels and image thumb and it works all pretty well and straight forward in my UITableViewController A.
Now I create a UITableViewController B (in Storyboard), which happens to have the exact same design/functionality for its custom cells (dynamic cells). So I switch the class of these cells to the MyCustomCell and give it a new identifier, cellB.
In UITableViewController B, I dequeue the cell in cellForRow... and use the new identifier cellB. Note: Using cellA here leads to a crash, more or less obviously.
But when the table view shows up, while running the app, the UITableViewController A works just fine, and the almost identical UITableViewController B does not work (empty cells).
In Storyboard, it looks sort of off a bit, because the custom cell is designable within the UITableViewController A but in UITableViewController B, it's just a simple, plain cell. Despite the class associated to MyCustomCell.
How would one avoid copy&pasting these cells to the other controller (and therefore heavily going back and forth between copies when making design changes) – and rather just properly re-use it?
What you are doing is correct. I don't know why its not working, it may be some problem with reloading the tableview; check with your datasource and the datasource method.
- (NSInteger) tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger) section
rather what you can do is: drag a
Viewcontroller
and then drag a
tableview
and make it dynamic and do the thing that you did earlier; it worked fine for me when I did so myself.
Saying the Cell is from a your custom class doesn't mean it's "designed" the same. What you really try to achieve here (and what I'm looking for) is some king of "Contained" Cell, but this is only doable with a ContainerViewController in iOS 6 I think. The other option is to use a XIB for that one Cell — that should work just as good, but then you lose the benefits of having an overview in the Storyboard.
I had a similar problem, I had created a custom cell with a uitextfield inside it. It was working well in the first tableview but not in the second. I figured out that the textfield's delegate was not connected to the custom cell. I connected the two in storyboard by making a connection from textfields delegate outlet back to the textfield.
In examples I have seen of UINavigationContoller and UITableView, switching to next view is usually triggered by tapping into that cell and pushing a different UIViewController on top of stack, but what I want is to switch to next view by pressing a next button in bottom of page, which I want it to load the same UITableViewController again but with different contents in each cell.
-Can I put that next button on bottom of page? and where
-Can I call the same controller (but showing different contents) and put on top of stack using the UINavigationController?
Because I want to be able to browse back previos pages.
You would generally do as you highlighted first and push a new UIViewController subclass onto the UINavigationController.
A UIViewController is supposed to manage one screens worth of content. If you plan on breaking that convention by presenting different information you are essentially going to have duplicated if statements to decide whether the user should be viewing the content from before or after the button was tapped.
UINavigationController's are good for hierarchal data where the content becomes more specific as you drill down. The UINavigationController will also manage the stack so that you can go to previous pages.
To achieve what you want to achieve (stated here) you should be using a UINavigationController with your custom subclass of UITableViewController when the user submits questions you receive your xml, parse it and then instantiate a new instance of your UITableViewController subclass and push it onto the stack.
You can add a button in the footer view of your table view. To achieve this have a look at tableView:viewForFooterInSection:. Then add an action to that button which allocs and inits the view controller with the new content and pushes it onto the stack.
Just make your UITableViewDatasource returning your number of rows plus one in the last section you have in –(NSUInteger)tableView:numberOfRowsInSection:. Set any content for that cell before returning it to the tableView.
Then only push a new UIVIewController, when the user touches that last cell.
You could also make the delegate of the UITableView returning nil on :
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath for the cells you don't want the user select.
I'm trying to replicate the functionality of the Music App (the one that comes built-in to all our iPhones/iPods.)
My goal is to have:
1) a Tab-Bar controller at the bottom, where every tab click loads a TableView.
2) Need to make sure that the Tab-Bar never disappears when these various table-views are loaded
3) the Table-Views must enable user to drill-down further and further into other table-views, sometimes 3 or 4 levels deep - but the tab-bar should never go away
4) One last thing: if possible, all the loaded Table-Views should NOT be Navigation Controllers, but regular UIViewControllers that then contain Tables (this is because it doesn't seem possible to resize tables when they're created as "UITableViewController"s, only when they're embedded into regular UIViewControllers, as-in, dragged and dropped out of the Objects Library onto an existing view.)
Anybody out there go some sort of tutorial or even code-template/engine type thing that they can share with us on how to do this?
As far as i understand, you know that it is possible to use UINavigationControllers as UITabBarController's controllers. What is the reason then not to use the navigation controllers ?
That must be completely what you want to do: create tables in the code or link it as the outlets with Interface Builder as you can either use UIViewController or UITableViewController (which inherits from UIViewController) as root and popped to stack of NavController.
Assuming you use XCode 4 here is the link to tutorial
upd:
for the header and footer views it is always better to use UITableView object's tableHeaderView and tableFooterView properties. Then you do not need to calculate the margins and update the view layout manually as it comes automatically.
Regarding the navigation, it is a general practice to set the controller containing the table to be the table delegate itself and then to use the method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
when you select one of the table cells, that method is called and you can create an instance of the next view controller, preconfigure it and then push to navigation stack. Back button comes automatically - and you are done. If you have the table in the next navigation controller, be careful while copy-pasting the methods from the previous-one, i.e. if you have wrang number of rows at
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
your application will crash.
My app features a UIWindow (inside of the AppDelegate?). Amazingly, (by mostly good luck), I've managed to get a NIB file to display inside of my AppDelegate's UIWindow. The resulting user interface which is displayed from my NIB file is comprised of three controls:
a UIView which serves as a sort of "background" (called "MainView")
a UITextView on top of MainView
a UITableView, also onto top of MainView, located geographically below the UITextView
I've spent the last month trying to populate that Table. Now I'm asking here.
Please help.
I recommend you take a look at Apple's View Controller Programming Guide.
Specifically, take a look at the prerequisites section (delegate objects, and Model-View-Controller).
Once you have a basic understanding of how view controllers and delegation work, look at (and implement) the UITableViewDelegate and UITableViewDataSource protocols. The basic way to do this is to create a UITableViewController class - XCode has a template for this class with stubbed methods.
create a UITableViewController subclass, then you need to set it as the datasource and delegate of the tableView, once there you just need to fill out the appropriate methods.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;