The iPhone's settings application is build around a UITableview. In some views there are additional texts between cells. For example in "Settings" -> "General" -> "Network" there is the text
"Using 3G loads data faster, but may descrease battery life" under a cell with an UISwitch. Any ideas how to implement this?
Images of what I mean can be found here:
http://www.tipb.com/2008/07/12/how-to-disable-3g-on-the-iphone-3g-for-more-talk-but-less-speed/
If you have a grouped table view, the tableView:titleForFooterInSection: method found in the UITableViewDataSource protocol and the UITableViewController class handles this for you:
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
if (section == 0) {
return #"Footer text for first section, goes below cells in that group.";
}
return nil;
}
To place that text between cells, you have to have multiple sections and tell your tableView:cellForRowAtIndexPath: method to place cells that you want beneath that text in the next section.
In XCode 6.1 you can specify footer text for Table View Sections in the Story Board.
Select your TableViewControler in the Story Board, then select the TableViewSection that you want the footer on. Then in the Attributes Inspector, in the Footer field, enter your text.
You can also create your own UIView of any type (images, texts etc) and add them to the table cell, by using the [[mycell contenView] addSubView:WHATEVER_IS_MY_VIEW_TO_ADD];
Related
In my app, i have addressbook which has a tableview to list contacts and in the right panel, i display the contact detail. In my contact detail page, i have fields like email, cellphone, workphone and homephone etc., and i have separate UIView for each field like cellphone, workphone etc., The Concept is to display the UIview of cellphone or workphone or such field only if there is a value for it. So its better to do it with a tableview right. My question is, can we add the UIView of those fields to the tableViewCell? i have attached the screenshot of the normal view. can i implement tableview here and add the UIView of each field to tableViewCell?
Create different custom cell for the different types you need and they should be with different identifiers. Then you can create a method that takes the correct identifier:
- (NSString *)identifierForIndexPath:(NSIndexPath *)indexPath
{
if (someCondition) {
return #"youCellIdentifier";
} else if (otherCondition) {
return #"yourCellOtherIdentifier";
}
}
Then you can use this method in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
If you have questions concerning this, feel free to ask.
CellView.frame=CGrectMake(0,0,150,50);
HomeView.frame=CGrectMake(0,60,150,50);
WorkView.frame=CGrectMake(0,120,150,50);
EmailView.frame=CGrectMake(0,180,150,50);
[Cell.contentview addsubview:cellview];
[Cell.contentview addsubview:HomeView];
[Cell.contentview addsubview:WorkView];
[Cell.contentview addsubview:EmailView];
Use custom UITableViewCells:
In your storyboard, create prototype cells. Drag there the elements you want for the different kinds of cells and position them appropriately. In your example, you will need one prototype cell for the blue cells and another one for the gray cell.
Subclass UITableViewCell. Create new Objective-C class for the new kinds of cells and select UITableViewCell as superclass.
Link the storyboard and the new classes. Go to the storyboard and select the cells. Enter as cell class the names of the newly created classes (instead of the default UITableViewCell. Create IBOutlets for the elements in the cells.
In your view controller, when creating new cells, set the values for the cell elements.
Hope, that helps you.
I'm new to developing applications for iphone and am studying alone.
I'm trying to make a view equal to the link below:
https://docs.google.com/open?id=0B26lA9znN3CUY3BBeW00NGo0RDA
I would REALLY make a view like this, with the switch button, the labels between the cells of the UITableView.
This example is used more than a UITableView? Or are several separate?
I could not find any examples like this. If there is a similar example would release it for download?
To replicate this view, create a table view controller with a 'grouped' style for the table - there's only one table. The table uses standard iOS views and styles (e.g., sections, footers, accessory views).
Section one:
Cell one: custom cell style w/ a UILabel # left and a UISwitch # right
Cell two: right detail cell style (UILabel # left and right) and disclosure indicator accessory
Section footer: return a UILabel w/ the text for section one by implementing the table view delegate method 'tableView:viewForFooterInSection'.
Section two:
Cell one: basic cell style (UILabel # left) and disclosure indicator accessory
Section three:
Cell one: right detail cell style (UILabel # left and right)
With the exception of the section one footer, all of this can be easily implemented in a storyboard.
The view you are looking at is not a normal UITableView, it is the Settings page of Skype.
Therefore you have to have a look at Settings.bundle. Here is a link to Apples Website that is describing it. Here is a good tutorial that describes how to set up a Settings page.
Update: There is an open source project available that lets you include the settings page directly in your application, as you wished:
http://www.cocoacontrols.com/platforms/ios/controls/inappsettingskit
I believe the free Sensible TableView framework enables you to achieve this using a very few number of lines.
I'm trying to create a grouped table view with two sections. For the first section I would like the width to be only half the screen. For the second section it would be the standard width. Also, next to the first section I would like to put a button.
How is this done?
Thanks!
To put a button in a section what I've done in the past is create a section that has no rows in it. Then, I respond to the - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section method with a view that contains a button that is rigged to whatever delegate I need. This will give you the appearance of having a button sitting in a section with no data. This is how buttons appear in the Contacts view/edit screens in the stock iPhone apps.
Table view sections are fixed with to the size of the screen. If you want the individual cells to appear narrower in one section and wider in another, then you can control the size of the view itself with the data source delegate, though you might have to set the background of the table view to transparent so users can actually see the smaller view on top of the table view.
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.
I'm really confused about that;
I have an example view. it contains an UITableview, this tableview contains approximately four or five rows. I don't know am i right or wrong way ? I'm trying that when the user click to the cell the table, i'm trying to add new custom cell onto the clicked cell with animation, this custom cell contains some action and information about the clicked cell. This is actually like to FaceBook start page on the iphone. In Facebook program when the user click to plus icon on the left side of row on start page view, it's working but how.
Can someone provide me an example code or any suggestions ?
Thank you very much.
EDIT :
Guys let me add more detail with some screenshots.
alt text http://img24.imageshack.us/img24/8159/img0398.png
As you can see on this picture, displaying list of data or some think like that.
When the user press the talk balloon (with plus icon) on the right side or per row.
alt text http://img682.imageshack.us/img682/1726/img0399.png
Custom cell or view (whatever) is coming from leftside to onto the selected cell,
with transition.
I think, my question was very clear now.
How can i do that ?
To show plus button in the cell you must set table view's editing property to YES and implement delegate's editingStyleForRowAtIndexPath method - return UITableViewCellEditingStyleInsert for the cell you need.
To add the new cell (with animation) to the table view you must implement
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
in your datasource - make necessary changes in your data source (the number of rows in table must be increased by one after this method) and call
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation for your tableview to animate changes.