How to load a loading view at the end of table view? - iphone

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)

Related

How to implement "Loading" in UITableView when scrolling down?

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!

iPhone - Adding new sections and rows into UITableView

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

Tool bar below table view

I need some clever hints here :)
I need to add a tool bar to my page containing a table view. If the table does not fill up the entire page I need the tool bar to be positioned at the bottom at the page but if the table is longer than the page I need the tool bar to be positioned at the end of the table.
What to do?! :/
Thanks a lot for any help,
Stine
Use the footer view of UITableViewDelegate....
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
Simply return a view from this and it will be placed at the bottom of the specified section (either a single section or your last one).
Also use..
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
To tell the Table view the height of the view.

Look like iPhone inbuilt contact applications image selection

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.

Custom View in UITableViewCell

I am trying to create a UITableView Section that contains two buttons aligned horizontally. This would be similar to the Contacts app, where on the bottom of a specific contact page they have buttons lined up to Text the contact and share the contact. However in my tableView, I want the two buttons to be placed in between other sections - so i can't set the table's header or footer view? How would i do this?
If I understand the question correct, you want something like this
section 1
your buttons
section 2
For this you can create custom headers/footers for sections instead of table. The methods you might be looking for are in UITableViewDelegate
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Look into subclassing UITableviewCell class, you can draw your custom view in there and use it, look at the UICatalog sample project in Apple site they do that there a lot