Pushing a button in a Scrollview without UserInteraction on - ios

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.

Related

How to show a footer view with custom text at the end of the UItableview

I have a UITableView to display search results. The user loads more results by scrolling to the end. When server has no more results, I want to show a text at the end of the tableview, that says "No more search results". I tried following code, but it is not working. Any suggestions on what is happening will be greatly appreciated.
UILabel *endLabel = [[UILabel alloc] init];
endLabel.text = #"No more results to display";
[endLabel sizeToFit];
self.tableView.tableFooterView = endLabel;
[self.tableView reloadData];
Following code may help you to solve out problem.
You can write this code to your viewDidLoad.
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
[footer addSubview:yourlabel];
[footer bringSubviewToFront:yourlabel];
yourlabel.text = #"whatever you want to write";
yourlabel.frame = CGRectMake(self.view.frame.size.width/2 - yourlabel.frame.size.width/2 , 30, yourlabel.frame.size.width, yourlabel.frame.size.height);
tbl_view.tableFooterView = footer;
However you need to increase the size of footer view of table.
I. Create a separate view in the xib of your viewController. By separate view I mean do not drag the view in the viewController's view as a subview, instead just drag it into the whitespace in your Interface Builder.
II. Now design the view i.e put a label in it that says no more data.
III. Now create an outlet of that view in your viewController.
#property(nonatomic, strong) IBOutlet UIView * tableFooterView;
IV. When there is no more data just write
self.tableView.tableFooterView = self.tableFooterView;
V. Set the width & height of the footer in viewDidLoad
self.tableFooterView.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 40);
VI. And when you do have data and don't want to show the no more data thing then
self.tableView.tableFooterView = nil;
//custom header for footer
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UILabel *endLabel = [[UILabel alloc] init];
endLabel.text = #"No more results to display";
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, self.tblView.frame.size.width, 40)];
[footerView addSubview:endLabel];
return footerView;
}
//Method To Get Height For Header and Footer
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 40.0;// your view height
}

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

UIScrollView in UITableViewCell not scrolling

I am adding a cell to a UITableView which has a scrollview, the code I have in the cell is :
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, 320, 44)];
UIView *labelView = [[UIView alloc] initWithFrame:CGRectMake(4, 4, 80 * _labels.count, 44)];
for (NSUInteger i = 0; i < _labels.count; i++) {
NSString *aLabel = [_labels objectAtIndex:i];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i * 70, 3, 60, 30)];
button.tag = i;
[button setTitle:aLabel forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor lightGrayColor]];
[labelView addSubview:button];
}
scrollView.contentSize = CGSizeMake(labelView.frame.size.width, labelView.frame.size.height);
[scrollView addSubview:labelView];
[self addSubview:scrollView];
However this does not scroll :(. If I have the same code segment outside the tableview and add this directly to the view, it works as expected. What am I missing?
Try [cell addSubview:scrollView];
Try adding the scrollView to the contentView of the UITableViewCell and maybe setting
self.contentView.userInteractionEnabled = NO
From the UITableViewCell reference doc
Discussion
The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.

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.

UIButton is not working in the header of my UITableView

I can't figure out why this UIButton is not working in the header of my UITableView. It's appearing there but the touch is not working.
The NSLog statement isn't triggering either. It's almost like it's beneath another view or something so that you can see it but the press action doesn't work.
thanks for any help with this
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *sectionHeader = [[UILabel alloc] initWithFrame:CGRectNull];
sectionHeader.backgroundColor = [UIColor clearColor];
[sectionHeader addSubview:self.topMapView];
// add map launch button
mapLaunchButton = [UIButton buttonWithType:UIButtonTypeCustom];
[mapLaunchButton addTarget:self
action:#selector(mapButtonTouch:)
forControlEvents:UIControlEventTouchDown];
[mapLaunchButton setTitle:#"ggggggg" forState:UIControlStateNormal];
mapLaunchButton.frame = CGRectMake(0, 0, 300, 90);
mapLaunchButton.backgroundColor = [UIColor redColor];
[sectionHeader addSubview:mapLaunchButton];
// [sectionHeader bringSubviewToFront:mapLaunchButton];
self.tableView.tableHeaderView = sectionHeader;
return sectionHeader;
}
- (void)mapButtonTouch:(id)sender {
NSLog(#"map button was touched");
}
I can see more than one mistake -
If your table has only one section (to verify this check for numberOfSectionsInTableView delegate) then remove this line -
self.tableView.tableHeaderView = sectionHeader;
Set sectionHeader.frame to something appropriate (not CGRectNull). The benefit of setting section header (versus table header view) is that when user will scroll the table rows then the section header will stick on top (float) and will not go away. (Plain style table)
Still the problem is not resolved, then please verify his method -
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 50; // depending upon the height of the sectionHeader
}
As pointed out by other poster, to capture touch event on UIButton UIControlEventTouchUpInside is preferred event.
EDIT - (as table header view implementation)
If you want to scroll it up then make it as table header (not section header). So remove all this from viewForHeaderInSection and put it inside viewDidLoad of your view controller class. Keep this line (don't remove it in this case) -
self.tableView.tableHeaderView = sectionHeader;
However, above points 2 and 4 still holds true.
If you change UIControlEventTouchDown to UIControlEventTouchUpInside?
One thing is the section header, and another is the table header. You are assigning the same view as both. I'm not sure this is the cause of your problem, but it's something to get you started.
Instead of implementing that method, on your viewDidLoad, create that view and assign it as the self.tableView.tableHeaderView
Additionally, the most common user experience is associated with the UIControlEventTouchUpInside (the action will not execute until the finger is lifted and still inside the button). However this likely has nothing to do with your issue. It's just a matter of when the action is called.
If this doesn't fix your issue let me know and I'll try to check if there's something else I've missed
Cheers!
If you add a view
self.tableView.tableHeaderView = ({
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 184.0f)];
you can add new components: UIImageView, UIlabel...
Its works for me!
I tested.
The final code:
self.tableView.tableHeaderView = ({
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 184.0f)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, 100, 100)];
imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
imageView.image = [UIImage imageNamed:#"avatar.jpg"];
imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = 50.0;
imageView.layer.borderColor = [UIColor whiteColor].CGColor;
imageView.layer.borderWidth = 3.0f;
imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
imageView.layer.shouldRasterize = YES;
imageView.clipsToBounds = YES;
UIButton *mapLaunchButton = [UIButton buttonWithType:UIButtonTypeCustom];
[mapLaunchButton addTarget:self action:#selector(mapButtonTouch:) forControlEvents:UIControlEventTouchDown];
[mapLaunchButton setTitle:#"ggggggg" forState:UIControlStateNormal];
mapLaunchButton.frame = CGRectMake(0, 0, 300, 90);
mapLaunchButton.backgroundColor = [UIColor redColor];
[view addSubview:imageView];
[view addSubview:mapLaunchButton];
view;
});
I had the same problem. Changing UIXXXXX from UILabel to UIView in the following line worked for me:
UIView *sectionHeader = [[UIXXXXX alloc] initWithFrame:CGRectNull];
and I didn't use:
self.tableView.tableHeaderView = sectionHeader;

Resources