I am working on iPhone application . This application contains plenty of web services. I need to show list in UITableView with page by page. How to show "Loading" and call web service when scrolling down the UITableview ? Please help me..
I assume that you are adding a custom cell to the bottom of your table view to indicate the end of the current data set. When you create that cell, set its tag property to a meaningful constant you've previously defined, like END_OF_TABLE_CELL.
Then use the delegate method tableView:willDisplayCell:forRowAtIndexPath to check if the cell about to display is your custom cell, and trigger a reload of the table's datasource.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//check your cell's tag
if (cell.tag == END_OF_TABLE_CELL) {
//Call your custom method to fetch more data and reload the table
// You should also remove this custom cell from the table and add one at the bottom
}
}
This way you will have a table that refreshes itself whenever a user scrolls down far enough to bring the custom cell into view.
Good Luck!
Related
I have a table view in which all are customised cells which is loading from 3 types of custom cells object classes.I have done paging also so that it will load 5 pages at the begning and then the second one like that.the problem is at the end of the table view cells i need to add a loading view.For that i used - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)sectionand added an activity indicator and loading label.but its position is not getting correctly.some times if the contents are more its position is not going correctly.Can anybody guide me the correct approach in achieving this?
You say : "loading view at the end of table view" whereas this function :
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
Will add a view at the end of a section that is different from what you want to do.
I suggest you to have a look at the following UITableView property :
tableFooterView
(documentation)
I have a UITableView to display a list of data.
The list will contain images, so I am loading images with lazy loading. Now I don't want to load the whole list at a time.
The loading should be like, first it should load some 10 records and when we scrolling down to the tableview, it should automatically load next 10 records as on.
For this I need to add rows when I am scrolling to bottom. The tableview may contain different sections.
So how can I add new rows and new sections at the end of the tableview while scrolling down?
Look at the Apple documentation about UITableView.
You can use the following method to add a row :
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
Firstly, the thing you want to do is known as Lazy Loading.
Means your table view will load images or show data in the cells which are currently visible to user. So have a look at this link. It provides sample code that might help you.
And to insert row, you can use
(void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
At
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == [yourArray count]-1)
{
//start fetching the next set of data in background asynchronously and when fetching is complete use delegate methods to reload or append your current UITableView , meanwhile start a activity indicator as footer to show loading
}
}
this is the effective method, if you try to implement synchronously when scrolling reaches bottom, it will make your device stuck
I created a custom cell for my table view and for the most part everything seems to be working fine, but when I select one of the rows (which takes me to another UIView), then come back from the subsequent view via the nav controller, the selected cell is not in highlighted state. How to display the selected cell in highlighted state when i come back?
any help is appreciated in advance, thanks.
when you are coming back from anotherview make sure that save the selectedCell and then in viewwillappear method reloaddata.in cellforindexpath write the code of selection style uitableviewcellselectionstyleblue
As #sachin said, you should save selected index path
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedIndexPath = indexPath;
}
and in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
You should check if indexPath is equal to selectedIndexPath,
but you should be aware that Apple discoureges that kind of behavior in HIG: http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html
In rare cases, a row might remain highlighted when secondary details
or controls related to the row item are displayed in the same screen.
However, this is not encouraged because it is difficult to display
simultaneously a list of choices, a selected item, and related details
or controls without creating an uncomfortably crowded layout.
I am currently developing an application in which a user is displayed a list in the form of a tableview. when the user selects a particular row, he/she can drag it to another row. When that happens an alert is displayed giving some specific information.Any idea as to how it can be done.?
What I am doing is that I am using gesture recognizers.When a particular row is selected, an image of the selected row is made which then is dragged to the specific table view cell.I am able to move the image but my problem is that if I dont put the imageView under a UIView, the dragging stuff does not happen.....
My dragging code is based on apple's touches sample code .
Update:
After trying for some time, I am able to almost implement this.I still have one doubt though.. I am creating an image of a cell once it is tapped.Then UIPanGestureRecognizer has been added to that imageView which it turn makes its movement possible .The only problem is how can I know on which cell the image has been dropped?
you should implement:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
which will return YES, and also implememt:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
//do whatever u want after row has been moved
}
and then call this function from tableView:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
to enter to edit mode.
This is a sample of an application with cells drag-n-drop in UITableView using native methods of delegate and dataSource of UITableView.
https://github.com/coderDove/UITableView-Drag-n-Drop
I have created an application in which i have to add users to the sqlite database.
Now the problem is I want the look of the standard iPhone Contact application Where while adding user we have the width of first cell smaller than other cells and the image before that cell..
Can you please give me the idea how such thing is possible.
How to make one cell small and rest others of normal size..
Thanks for any help in advance
There are three UITableViewDelegate messages you can listen for to adjust height
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
However, even thought I didn't write Contacts.app I have a feeling they are also using
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
To adjust the views as well. Remember, you don't have to pack everything into a single monolithic custom table view cell. You can create multiple custom table view cells and load them each appropriately depending on the index path.
The contact detail view is a grouped tableview. Each cluster of cells is a section. The top section is a single custom cell with two subviews that look like squashed tableview cells. The left view shows the contact's photo. The right view shows the name.
To reproduce, create a custom UITableView subclass and lay it out like you want either programmatically or in Interface Builder. Then in the tableview delegate's cellForRowAtIndexPath check indexPath.section and return the proper row for the section.
It appears that the Contacts app uses a custom tableHeaderView when presenting the contact details with an image and label. A similar implementation is included in the sample project iPhoneCoreDataRecipes. The RecipeDetailView loads a separate nib in tableViewHeaderView that is used to set the tableView.tableHeaderView property. Have a look at RecipeDetailViewController.{h,m} and DetailHeaderView.xib. When the Contacts app switches to editing mode, the headerView appears to be swapped out for another view that has a button and a tableView with a single cell. This will allow you to set up a separate tableViewDelegate to handle the Name parts of the contact and a delegate to handle the address / telephony details.