SegmentControl doesn't move with TableView scroll - uitableview

The scene currently in view is "RunTestViewController". As you can see there is a segment control embedded.
Everything runs fine, the segmentcontrol works, however when I scroll the segment control stays put and end up on top of the cells.
Is there a way embed the segment controller into the tableview so it moves with the table?
Thanks,
**EDIT:
------------------**
I have added this code in the viewDidLoad section:
UIView *headerView = [[UIView alloc] init ];
[headerView addSubview:resultsSegment];
self.tableView.tableHeaderView = headerView;
This allows the segmentcontrol to move when the table view scrolls, which is great, however the segment control is now unclickable, any ideas?

You want to embed a view or control into a tableview so that it scrolls with the tableview? You should put the view or control into the tableview header.
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,200)];
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
[headerView addSubview:segmentControl];
self.tableView.tableHeaderView = headerView;

Related

Pushing a button in a Scrollview without UserInteraction on

I am using an UITableView with headers and footers, the whole TableView has horizontal UIScrollViews inside. I use it as a lock titles function, like in Excel.
The UserInteraction is disabled on the UIScrollView in the UITableview Header and UITableView Footer and only scrolls when the body scrolls.
In my header I now have a button which is situated in the UIScrollViews ContentView and I need to be able to interact with it, which does not... Has anyone come across this in the past?
Much of the unneeded code has been omitted...
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UITableViewHeaderFooterView *viewHeader;
UIButton *flow;
viewHeader = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(0, 1, self.tableview.frame.size.width, 48)];
UIView *thisContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, contentWidth, 48)];
flow = [[UIButton alloc] initWithFrame:CGRectMake( flowRate.frame.origin.x + flowRate.frame.size.width + 5, 14, colWidth1, 20)];
[flow.imageView setImage:[UIImage imageNamed:#"ic_flow"]];
flow.imageView.contentMode = UIViewContentModeScaleAspectFit;
[flow setContentMode:UIViewContentModeScaleAspectFit];
[UniversalMethods tintImageviewInButton:flow withColor:BRIGHT_BLUE];
[flow addTarget:self action:#selector(showSortingAlert:) forControlEvents:UIControlEventTouchUpInside];
[thisContentView addSubview:flow];
[thisScrollview addSubview:thisContentView];
thisScrollview.contentSize = thisContentView.frame.size;
thisScrollview.tag = scrollTag;
[thisScrollview setUserInteractionEnabled:false];
[viewHeader addSubview:thisScrollview];
return viewHeader;
}
When userInteraction is disabled on a view, it also prevents touch events from being passed down to its subviews. You'll need to enable userInteraction on the scrollview in order to tap the button. You can set isScrollEnabled to false in order to prevent the scrollview from scrolling.

Custom View with dynamic Height as UITableView Header ios xcode

In my project,i have a 1.MovieplayerView,2.a label with dynamic content,3.a tableView with variable number of rows.
I was doing this with all these views in scrollView.But i always have the issue with dynamic height of the label.it sometime overlaps the tableView.
I came to know that we can use customView as the tableView header.How this can be done with variable content Height and autolayout?I am new to iOS.Any suggestion ??
I know how to add a view as the header to a table.But when the contents in the view changes,it overlaps the contents of the tableView.
I went through
How to resize superview to fit all subviews with autolayout?,How do I set the height of tableHeaderView (UITableView) with autolayout?
Can some one give a simple example on how to do this?Or tell me if it is better to use a scrollview and add all these views as its subviews? any suggestion would be realy helpful.Thanks.
In viewDidAppear,
1. Get the height of the dynamic content, then set the height of your tableHeaderView accordingly.
2. Set the headerView again so the table view can refresh:
self.tableView.tableHeaderView = headerView
Try using following code is this what u want to achieve can u clearify me please
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 200, 40)];
NSString *string = [NSString stringWithFormat:#"/ %#",selectedCategory];
label.font = [UIFont fontWithName:#"Helvetica" size:15.0];
label.textColor = ThemeColor;
[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:0.933f green:0.933f blue:0.933f alpha:1.00f]];
return view;
}
Don't forget to place this in nib of UITableView
It's hard to interpret your question regarding your use of the scroll view. If what you want is a custom view as the table view header, you could override this method in your table view class:
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section

Adding a UISegmentedControl to UITableView

How do I add a UISegmentedControl to a UITableView?
Similar to the image found here:
http://cdn.imore.com/sites/imore.com/files/styles/large/public/field/image/2012/08/iHomework-for-iPhone-managing-assignments-and-tasks.jpg
I would like to have a UISegmentedControl that sticks underneath the navigation bar.
This is what I've tried so far:
In my viewDidLoad method, I've created a UISegmentedControl
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:#"One", #"Two", nil]];
segmentedControl.frame = CGRectMake(50, 0, 220, 100);
[segmentedControl addTarget:self action:#selector(segmentedControlHasChangedValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentedControl];
However, the segmented control overlaps with the tableview itself.
EDIT
Additionally,I would like to create this uisegmentedcontrol fully programmatically as I don't want to use a nib file.
self.tableView.tableHeaderView = segmentedControl;
If you want it to obey your width and height properly though enclose your segmentedControl in a UIView first as the tableView likes to mangle your view a bit to fit the width.

iOS: custom view in "viewForHeaderInSection:" delegate method hides for section = 0

I have some problem with UITableView, with it's Header. I need to set custom UIView in every section header, but the problem is in displaying header in section with number 0.
On the picture I tried to show my problem - on the left side its design what I need to do and on the right side it's what I did. This is the comparison of screens
I need fully displaying of badge with character in any section.
Thanks for your help!
You could set transparent tableHeaderView to your tableView with the height that is being hidden. Like this:
UIView *tView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, DESIRED_HEIGHT)];
self.tableView.tableHeaderView = tView;
Good Luck!
make a custom header like this
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *viewHeader = [UIView.alloc initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 28)];
UILabel *lblTitle = [UILabel.alloc initWithFrame:CGRectMake(6, 3, 136, 21)];
[lblTitle setFont:[UIFont fontWithName:#"HelveticaNeue" size:13]];
[lblTitle setTextColor:[UIColor blackColor]];
[lblTitle setTextAlignment:NSTextAlignmentLeft];
[lblTitle setBackgroundColor:[UIColor clearColor]];
[viewHeader addSubview:lblTitle];
return viewHeader;
}
Make a NSArray for Header Titles. and get this title in above method
Looks like it might be an iOS7 specific issue with the tableView hiding partially behind the navigation bar? Have you tried running it on iOS6? I would guess that you wouldn't have the same issue. Try adding the following code to your table view file and see if it helps:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// if this is ios7 this code will make the view appear properly below the navigation bar
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;
}
}
Well its very simple solution. Just create your custom UITableviewCell class with manually nib file inside that drag and drop UITableviewCell and then set imageview, label etc. On UITableviewCell and then just load the same inside your viewForHeaderinsection. As we know this method returns view. So when load custom UITableviewCell class inside this method just return cell, as it is also inherited from UIView.

UITableView first section hidden by viewForHeaderInSection

I have a UITableView which is a grouped table view. I am trying to add an image as the header of the table view (and only for the first section). The problem I'm having is that the image is covering the first section of the tableview.
Here's the code:
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 80)];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://www.eventsforacausesf.com/uploads/8/7/3/0/8730216/3416277_orig.jpg"]];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, headerView.frame.size.width, headerView.frame.size.height)];
imageView.image = [UIImage imageWithData:imageData];
[headerView addSubview:imageView];
if (section == 0) {
return headerView;
}
return nil;
}
For example, in the image below, the first section of the tableview is hidden behind the image. I need to move that section below the image.
What you're setting with that data source method is a header for a particular section of the table view, but it sounds to me like what you want is to set the tableViewHeader of the table view itself. Set your table view's tableViewHeader property to your header view instead of returning the header view as a section header. Then you'll get the standard iOS header vs. content layout.
You also need to implement tableView:heightForHeaderInSection: to return the height of the image view.

Resources