Custom IOS separator - iphone

How is the 'or' separator below made? is it an image used in the section header?

if that's really done with a table view, then it's done via a delegate method of "tableView:viewForHeaderInSection:".

Yes, it is an image used for section header.

That login page is modifying the header/footer views of the UITableView.
When you are setting up the table view you need use the following UITableView delegate methods in order to create a header and footer view in each section of your table view.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// Set your custom view for the header in the section
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// Set your custom view for the footer in the section
}
- (CGFloat) tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
// Set the height of the header in each section
}
- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
// Set the height of the footer in each section
}
NOTE: If you notice the first two methods return a UIView therefore it does not just have to be an image. You can create any custom view you want and place it in the tableView header/footer. The view could be UIKit elements, UIImage, or even made with CoreGraphics.

Related

How to hide empty UITableViewCells showing in UITableView with plain style - IOS?

UItableView is showing with empty rows like below...
how to hide it without changing the tableview style. Do I need to resize the table View, if so how can I know the height exactly to set.
self.tableView.tableFooterView = [[UIView alloc] init];
you add UIview in footer of uitabeview use of xib or tableview delegate method
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
{
return 1;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
{
return yourview;
}
What I had done in one of my projects was to set the tableview's background color to clearColor and separator to none.
Just drag and drop a view from object library to the TableView empty shell in storyboard. Make the view as footer of the table view (in document outline drag it below the cell's if it is not already at below) make the height of the view '0'. You will not see the view in storyboard because its height is '0' but when its runs it will hide the cells. I think that should work.
Why don't you put some logic into your
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
function?
Just return the number of cells which are really filled with data

Padding on TableViewCell

I want to add padding to my table view cells. Thought I could do something like this but that didnt work.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
return cell.frame.size.height + 20;
}
See the below link. Explains the basics of getting a variable height (for cells) UITableView along with proper padding that your require. Example just includes text. Change it to suit your requirements within the cell.
http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/
Are you sure you placed this method in your delegate? it also depends on which cells. There are other methods...
// UITableViewDelegate Method
- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
}
// UITableViewDelegate Method
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
}
also, if you are using the contentView of the cell then you will need to change the frame of your custom view
When adding your cells you will need to set the y value of the cell's frame to half your padding to make it start at the right place. Also ensure that the cell does not have flexible height or it will expand to fill the height of the row.

Fixed button at bottom of UITableView

I have a view controller which has a tableview subview. I have made the tableview height smaller, leaving about 46 pixels for a button that needs to stay at the bottom and not scrolled with the table.
I have played around changing the height of the table view (in IB) and it doesn't seem to change anything. Any help would be appreciated.
You need to have the UIButton at the same level as the UITableView - both are subviews of the main view. Do you have the UITableView as the view of the view controller?
This can be done programmatically in the UITableViewDelegate:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// Build a custom view
// ...
// Build a custom button
// ...
[customFooterView addSubview:button];
return [customFooterView autorelease];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 53.0; // return your button's height
}

Redraw or Reset table view header and/or footer

Is there a way other than [tableView reloadData] to refresh table header and/or footer? With respect to both:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
OR
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
For example, I'm showing a small summary in the footer. When the data in the row changes, the affect should be reflected in the footer as well.
Create a UILabel and set it as section header/footer. Update the UILabel whenever you want.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return sectionFooterView;
}
- (void)viewDidLoad {
// create sectionFooterView in Interface Builder, change the frame here
// use Font-size:15 , BG-Color: clearColor , text-Color: RGB=(97,105,118)
// and Text-alignment:Center to look like table view's original footer
sectionFooterView.frame = CGRectMake(0, 10, 320, 12);
}
- (void)changeFooter {
sectionFooterView.text = #"Footer";
}

How do I populate a predefined UITableView to a view using the interface builder

I've created a custom UITableViewCell with a label and a text field.
I want to create two cells in a group to represent a nice username/password input mechanism.
I've run into some troubles figuring it out (things like the delegate/dataSource).
Is there a more direct approach to just add those two cells and get the data inserted into the text fields from code?
P.s. I want the TableView to be only at a part of my screen, the other part will be an "Enter" button...
Plus, if it can do it via the interface builder that would be great.
Although I agree with jer, some pointers about how to still use IB to make table view cells.
Add the cells to your NIB (at root level) and make them look good. Add two IBOutlet UITableViewCell *cell0, *cell1; to your header. Hook up the cells in the NIB to these outlets.
In the class which is your dataSource, do something like:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch ([indexPath row])
{
case 0: return cell0;
case 1: return cell1;
}
NSLog("Something bad happened");
return nil;
}
Interface builder doesn't know about your table view data. If you are confused about setting up a data source, then read the documentation, try the sample code, explore until things make sense. Ask when you get frustrated.