I have a grouped UITableView that has basic data inside it, but I would like to start the UITableView at a certain section when the app loads, can this be achieved?
Thanks
Mark
Sure - use the scrollToRowAtIndexPath method of UITableView. Using the index path you specify which section and which row you would like to scroll to. Presumably you would like to see it at the top of the table so in the method call specify UITableViewScrollPositionTop.
Related
I'm developing an iOS application in which i have a UITableView containing list of people coming from web-service and i have a more button on bottom. When user clicks on more it calls a service which provides some new people for the list. Now i want to add this list with the previous tableView list without reloading the whole tableView. how do i achieve this.
Any help would be really appreciable. I can provide my code of more button where i'm calling the service to get the data from service.
UITableview provides several APIs for manipulating the content. You should use the
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation: (UITableViewRowAnimation)animation;
method. The way how they should be applied is described in the Table View Programming Guide.
Practically, when the button is clicked, you start the network request for the list of names and when that finishes, you add the rows to the table with the above API.
Note: as long as you do only this modification to the table view, you don't have to use the beginUpdates, endUpdates methods. If there are multilple changes carried out at once (deletion, addition, reordering) then the beginUpdates/endUpdates is necessary.
Have a look at UITableView's - beginUpdates; and - endUpdates method.
In between calling these you'd have to insert the rows into the table view. If you are using UITableView's - insertRowsAtIndexPaths:withRowAnimation: method you can even skip the begin- and endUpdates.
Make sure to insert your new objects to your data source object before calling insertRowsAtIndexPaths:withRowAnimation:.
If you don;t want to reload the table then, at least, you have to call
insertRowsAtIndexPaths: withRowAnimation:
except that you can't show the newly added data in your table view.
As per my experience , It is not possible to add/display new names to table view without reloading it.
But you can achieve your task as follows ;
You can set arraCount(one varaible) for namesArray count. After calling webservice, you can increment arrayCount varaiable and reload the table view , which will display new added names in the table.
Hope this will help.
I am trying to make an bunch of links on the right side of the uitableview to jump to the various sections in the tableview without having a searchbar at the top.
thanks
Sure can. Just implement a couple of methods in your table view’s data source: -sectionIndexTitlesForTableView:, which should return an array of titles, and -tableView:sectionForSectionIndexTitle:atIndex:, which returns the corresponding section once the user clicks on a section title.
I´m new trying to make some apps using objective c, so I´ve an idea using uitableview but I don't imagine how can I get this.
I´m trying to do something like you do in a spreadsheet where you have a fixed header and the first column too
So when scroll the uitableview vertically the header will stay visible at top of the table and rows will change
And finally when you scroll in horizontal direction the first cell of the row will stay visible and will change the header depending of how you scroll the uitableview
I hope you could give me an idea how to get this, because I don't imagine how to do this, also I don´t have a lot of experience with this programming language.
Thanks!
In a non-grouped table, section headers "stick" at the top of the table as the table scrolls. You can provide a custom UIView (or sub-class thereof) for a section header through the delegate method –tableView:viewForHeaderInSection:. This header view could be created on-the-fly programmatically or loaded from a NIB file. Either way, you can have it contain whatever you want, even update it as the app runs (provided you have given yourself access through ivars or class variables to the views contained in your header view.) If you go this route, you'll want to be clever about allocating resources that comprise this view, so that you are not constantly allocating new resources! This delegate method can be called frequently, and on all but the first call you could simply return the previously created (but updated as and if necessary) header view.
UITableView isn't designed to do this, although I am sure you could figure out some way eventually.
My approach would be to use a fixed UIView of some sort (possibly a UILabel, etc) in a UIViewController's nib as the header/locked cell, and add the UITableView under that. You couldn't then use a UITableViewController, but would have to implement the delegate and dataSource methods in your UIViewController, and use a UISwipeGestureRecognizer to pick up the gestures from the tableView and update the other views.
I've done this by adding a UIView that mimics the first cell in my table. In my case I am using a subclass of UITableViewCell, but that is perhaps not relevant. Normally this view is hidden with an alpha of 0.
If you view controller is the delegate of the UITableView then it will also be the delegate for the inherited UIScrollView. So in your view controller you can implement scrollViewDidScroll. When the scrollView's contentOffset is positive I set my custom view's alpha to 1 (I also do some small size tweaks to make sure there is a perfect match), and when the contentOffset returns to 0 or negative, I reset the alpha back to 0.
prepend the first row of data in your array to what ever in the first row is your headings, put the text in bold with attributed text, It wont be sticky but you will have headings...
How do you know that you scrolled using the UITableViewIndex ?
I have some basic info to show on my cells, and when I jump/scroll I need to retrieve info about thoses cells by a request for a group(page) of items.
So in order to request only thoses I've stopped to, I need a way to know that I've stopped scrolling (I used scrollViewDidEndDecelerating) but with the UITableViewIndex we ca just jump to another index or scroll though them.
The only feedback that you get is in the UITAbleViewDelegate protocol - none of these report that the table view has scrolled.
However, you will get calls to tableView:cellForRowAtIndexPath: calls to your data source - this will tell you that the table view has moved enough to want a new cell.
Also, you have the visibleCells property of the UITableView itself to see where you are in the table?
It might help if you put more detail into your question - why do you need to know that a scroll has happened?
The UITableView inherits from UIScrollView so you can also implement the UIScrollViewDelegate methods such as scrollViewDidScroll. When the table view scrolls, these will be called.
However, if you explain why you need to know whether the table view has scrolled, there might be a better answer.
Edit:
From your updated question, it's still not totally clear whether you need the scrollview delegate methods.
If you just need to update the contents of the cells themselves, put that in cellForRowAtIndexPath and the table view will automatically call it when the cell comes into view.
If you need to update something outside the table view, you might still be able to do it in cellForRowAtIndexPath or you can handle scrollViewDidEndDecelerating: and then use the table view's visibleCells or indexPathsForVisibleRows methods to get the list of cells currently visible.
I have created a UITableView with multiple columns to display a Football League Table. Now what I really need is a header to label each column which will ideally sit at the top of the table view. How would I do this?
Instead of setting it as the header for your first UITableView section, it would make more sense in your situation to set it as the header to your entire table. This can be done with the tableHeaderView property of UITableView. For example:
UIView *myHeaderView = ...
[myTableView setTableHeaderView:myHeaderView];
You could create a custom UIView and set it as the first section header of your UITableView. Return it in your UITableViewDelegate's tableView:viewForHeaderInSection: method. You simply need to design it so that it aligns with the "columns" inside your custom cells.
This is sort of a weird interface for an iPhone app, assuming you are trying to replicate the look and feel of an HTML table, with headings, cells and etc.
If this is what you want, why not just use a UIWebView object to display your table?