How to place two buttons on top of tableview - iphone

i have been looking, but can't find my answer.
my question is how to make a tableview with two buttons above it.
here is a pic of something i would like to do.
I have the grouped tableview, but can't figure out how to make it look like the image.
thanks for the help
http://img137.imageshack.us/i/imagezjb.png/

Create a view with your two buttons as subviews, then set the tableHeaderView property on your table view to be that view.

#LucasTizma's answer is valid but you can also return views for header sections by implementing the method below, which returns a UIView. In this case, you will be able to return different views for different header sections so if for instance you had a header for Games and a header for Utilities on the same tableView, you could return different images/buttons for each header (i.e. a special game promo in the game section and a different one for Utilities).
Basically the process is the same: you create a UIView, add the buttons/images as subviews and then return it on the method.
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
Cheers,
Rog

Related

setting an ImageView as a background for sections in a grouped uitableview

is there any possible way to set a UIImageView as a background for a section (let's say section #3) in a grouped UITableView?
I'm not asking about viewForHeaderInSection 'coz I tried it but didn't work as expected.
thanks so much in advance ...
My guess is that if you were to think very creatively, you could come up with a way to essentially swap the UITableView's backgroundView property as different sections are visible. This doesn't strike me as particularly elegant given that multiple sections might occupy the visible screen at one time, but perhaps I don't understand the question clearly.
The short answer is that there is not a defined/simple way to achieve this. The composition of a section is far removed from the background of a UITableView, and essentially the architecture isn't setup for what you want. I wouldn't assume to know the details of your implementation, but I would also urge caution: The visual and architectural characteristics of UITableView's are pretty well-considered. My personal opinion (again, I haven't seen what you're working on), is that different section backgrounds might overwhelm the user experience in many cases. I can also see cases where it may be a nice UI touch if executed properly.
In this case, if you still want to do it, here is the approach I'd take:
Essentially you're going to watch the position of your tableview's cells. You could do this in scrollViewDidScroll, or tableViewWillDisplay cell - or other places, I'm sure. But you need to know which cells are scroll on and off the screen, and you then need to be able to ask the upper-most-visible cell what it's section is. Once you've established which section it is you should currently be displaying, you can use that to scroll your own set of views representing each section's background.
Essentially, you're going to create each of your dynamic section background views in code, just UIView's, each with it's backgroundProperty set to a repeating pattern (obviously, heights will be dynamic). Add all your section background subviews (or preferably do it lazily) to your UITableView's backgroundView.
Now, as your scroll view scrolls, you're going to observe which rows and sections are coming in and out of the table's view. As rows in sections are scrolled, calculate the height of the section background (multiply the quantity of rows in the section by their heights) and adjust it's Y axis, which is sitting in but clipped by your tableView's backgroundView. As sections scroll on, you'll update the Y offset of the relevant section's background view. Phew!
Another idea might be to toss all your section background views, laid out vertically, in a UIScrollView, user interaction disabled. Place that scroll view in your table view's backgroundView, and then figure out the math to essentially "forward" scroll events from the tableview's scrolling view to your background scrolling view.
This will probably take a bit of work to find an implementation that keeps your animations all smooth and in sync, but, it's an approach that I think could be made to work.
Use myTable.tableHeaderView = customHeaderView if your table has only one section.
viewForHeaderInSection might not have worked if you didn't return an object of type UIView or a subclass in your method. Add some code from your viewForHeaderInSection method to your question for a more precise answer.
EDIT- If by viewForHeaderInSection didn't work as expected, you mean that the header was clipped, then it might be because you have not have implemented the following method:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
If not implemented, each section's height is set to an iOS default value.
create a custom headerView that looks something like this.
.h
#interface CustomViewForHeader: UIView
#end
.m
#import "CustomViewForHeader.h"
#implementation CustomViewForHeader
-(id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self != nil) {
UIImageView *bgImage = [[UIImageView alloc]initWithFrame:self.frame];
bgImage.image = [UIImage imageNamed:#"bill_headerBg.png"];
[self addSubview:bgImage];
}
return self;
}
#end
use it like:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 50.0;
}
-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {
CustomViewForHeader *customView = [[CustomView alloc]initWithFrame:CGRectMake(0,0,320,50)]
return customView;
}
I recall something about methods to find the rectangles of each section. Having those, you could appropriate sized images to the scroll view underlying the table view.
Aside from that, you could put the background image into the background of the cells themselves. When the tableview calls for a cell in a given section, you can pick the appropriate image or image tile.

UITableView with custom index view

What I'm trying to do is to customize the look of UITableView index. After some search I came to the conclusion that this is not possible and I have to make a custom view to accomplish something like the screen shot below.
example http://img705.imageshack.us/img705/8573/57screenshot20111231at9.png
My table view doesn't have sections, so what I want to do is to scroll one "page" down or up when one of the little dots is tapped. Also I want the user to be able to swipe over the view to jump over pages quickly just like the standard table view index.
I will be grateful if you provide me with an example of something similar to this or at least some guidelines on where to start.
As long as you don't mind the 'dots' being a fixed colour, this is indeed possible to accomplish with the already provided methods. You need only use the 2 methods:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
You will also need a UIImageView that holds the transparent image you have over the selected 'dot'.
In the first method, return an NSArray for the form: [NSArray arrayWithObjects:#".", #".", ..., #".", nil];. This will enter in 'dots' in the side bar, where each dot represents 1 section of the UITableView. When the user taps on one of the 'dots', the UITableView will move to the corresponding section. Since you want the sections to be each 1 page length, just section your data accordingly.
As for the second method, this is where you adjust the frame of the UIImageView holding the transparent image which covers the selected dot. Just change the .frame. property to line up with the new selected section. You'll need to do a bit of math to get this lined up right, but it's fairly easy.
You'll also need to use the UIScrollViewDelegate methods to handle moving the transparent image while the user is scrolling. They are:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
These will allow you to have the UIImageView move to the appropriate section while the user is scrolling. Again, you'll have to do a bit of math to get everything lined up perfectly.
Hope that Helps!

How do you build a 3 column layout of varying height images for the iphone

I need to create a screen that scrolls vertically - like the tableview but I need 3 columns and within those 3 columns I need to add images of varying height - so this will not fit into rows that a tableview can provide.
Should I create 3 tableviews and lay them out side by side - or something else. I think I could build this by simply positioning the images using coordinates but I wanted to benefit from methods that the table view can provide.
If you want the columns to act stuck together, so that they all scroll simultaneously, then I think best approach is to use UIScrollView with the images added in the correct placed "by hand." UITableView and friends is not built to handle non-lined up columns.
added If you do use a UIScrollView, and you have a large number of images you want to display (that is, the user can scroll for a long time), then it would be wise to recycle your UIImageView objects that are scrolled off the screen. This is what UITableView does with UITableViewCell objects, and that's why UITableView wins. You can win, too, if you code carefully.
Three table views would work, but in order to keep things neat and from the same datasource, I would consider using a subclassed UIPickerView and the UIPickerViewDelegate/UIPickerViewDataSource.
Particularly necessary methods:
// UIPickerViewDataSource
– numberOfComponentsInPickerView:
– pickerView:numberOfRowsInComponent:
// UIPickerViewDelegate
– pickerView:rowHeightForComponent:
- pickerView:viewForRow:forComponent:reusingView:
According to my opinion You should have to take three UITableView in xib file and take its IBOutlet then give each UITableView an unique tag and then implement UITableView's Delegate methods and in that Methods Check for Tag and then assign values.
Along With this, the other solution, you can also use UIPickerView and then implement UIPickerView's delegate methods also..
Happy Coding !!!

UITableView: delete section controls

Is there a way to add delete controls, like in UITableViewCell, on a table section? I see two ways:
Use table cell instead of sections.
Write own UIView section class, which will show delete controls.
Regarding the first way - as I think, it could be an easiest way in my situation.
The second way may be better from the implementation point of view, but it will take more time.
May be I missed another way? Any suggestions?
The only way I see is to provide your UITableViewController Delegate or Subclass with the method called:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
This gives you the power to display any kind of UIView as a section-header. within this view you can place controls that enable the user to delete sections.
I hope this helps a bit.

UITableView has a custom section header view which disappears

The tableview, custom table header, and custom section headers are loaded from a NIB. The tableview is grouped.
When the view loads, the first section header doesn't show up. If I scroll down, the other section headers will appear at first, but will disappear as soon as the section above them touches the top of the screen.
If I scroll back up so that a disappeared section header is off the screen, then scroll back down, it will usually reappear.
The problem is fairly consistent but not entirely- sometimes I have to scroll up and down several times to get a header to reappear. Any ideas as to what could cause this?
I fixed it- I was using one UIView for 3 sections, changing the text appropriately then returning it. Creating separate UIViews in the NIB for each section fixed the problem. So I guess you can't do that.
Your custom views must be (or descend from) UILable or UIImageView objects. You may need to manually set row height for the headers to get custom views to load and display properly.
You should review the details in the UITableViewDelegate protocol.
Specifically, look at these methods:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
and
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
Part of the discussion on the tableView:viewForHeaderInSection: method states:
This method only works correctly when tableView:heightForHeaderInSection: is also implemented.