UITableview covering button - ios

I tried to make floating button on top of uitableview, I already set uitableview to back and the button is in the front on storyboard but when I run the application the table covering the button. How can I make the button to always on front?
Here is the screenshot:

Try to bring your subviews on top of tableview.
- (void)viewDidLoad {
[super viewDidLoad];
[self.view bringSubviewToFront:yourButton];
}

Set autoresizing mask of your buttons from bottom then check. If buttons are not appearing then add this code to in your viewDidLoad method -
[self.view bringSubViewToFront: btn_Cancel];
[self.view bringSubViewToFront: btn_Delete];

Related

How to add a button to bottom of UIPageViewController

I would like to add a button to my UIPageViewController just like the bottom right button of the iOS Weather app.
I would like to know what is most correct and clean way of doing it.
Should I access the PageControl somehow and add a subview with the button I want to add or should I hide the Page Control and add a toolbar at the bottom of the view?
Any simple snippet would be most welcome.
Thank you!
In viewDidLoad, add the button to the UIPageViewController's view.
In viewDidAppear, bring the button to front
```
- (void)viewDidLoad {
[super viewDidLoad];
// Add the button
[self.view addSubview:button];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Bring it to front so it appears in front of the UIPageControl
[self.view bringSubviewToFront:button];
}
```

Scroll view scroll indicator visible despite being turned off

I've just added a UIScrollView and when the user scrolls (horizontally) the scroll bar indicator appears at the bottom of the screen (then it disappears when the user stops scrolling).
However in the VC's viewDidLoad I'm setting the SC's showsHorizontalScrollIndicator to NO, also in IB in the Shows Horizonal Scrollers check box is set to off.
So how can I make these scroll indicators permanently never appear?
The horizontal and vertical indicators are type of UIImageView by default. So, if you want to remove it permanently then do this
//Assuming myScrollView is of type UIScrollView
- (void)viewDidLoad
{
[super viewDidLoad];
for(UIView *subview in myScrollView.subviews){
[subview removeFromSuperview];
}
}

Add a button to float on top of a ViewController, Path inspired

I am trying to build a button that will be floating on top of a ViewController, it should remain in the same position statically while the viewcontroller beneath it can scroll up and down.
I designed my own button class and in the viewdidload of the parent Viewcontroller I am doing this :
- (void)viewDidLoad// this is the parent viewcontroller
{
[super viewDidLoad];
customButton *floatingButton = [[UIButton alloc]initWithFrame:(self.view.frame)];
[floatingButton setLocation:CGPointMake(300, 430)];
[self.view addSubview:floatingButton];
[self.view bringSubviewToFront:floatingButton];
This is not doing it, as in when I run the button doesn't show up, only the view controller.
How can I achieve this?
I don't think that you're initializing your button properly. initWithFrame is a UIView initializer, being called by a regular UIButton. I don't see how you would get anything but an empty view here.
If you have a custom initializer for your custom button you should use
[[CustomButton alloc] myCustomInitializerWithFrame:frame];
Thanks guys, but the error was on my end, I wasn't initializing the frame properly, so the button was there but had a height and width of (0,0).

Add clickable and fixed subview to UITableViewController?

I'd like to place an ADBannerView object onto my UITableView screen statically, what means that I want it to always stay above my toolbar (self.navigationController.toolbar), even when the user is scrolling the tableview. I've solved this by adding by ADBannerView as a subview to my toolbar and given it negative values for the frames origin:
[self setBannerViewSize];
[self.navigationController.toolbar addSubview:bannerView];
The only problem is: I can't click and open the iAd this way - I can see the banner but nothing happens when I tap on it.
Since I'm also using a refreshControl, the option to use a UIViewController instead of UITableViewController and add a tableView manually wouldn't work for me. Is there any other way I can get my ADBannerView statically showing in my table view controller AND still being tappable?
Thank you in advice!
Yay!! After all I succeeded in solving this (really annoying) problem by myself (and a lot of reading around)!
First, I found this really world-changing post. Basically this post handles with the topic that a UITableViewController uses self.view for its tableView property, so overriding the tableView property (or synthesizing it manually) plus giving self.view a new view (from application) and adding tableView as its subview would make it possible to reach the real superview of tableView.
But this still didn't solve my problem, although I was sure it would, because it all made sense. My bannerView appeared in the right place (and was fixed) but it still didn't do anything when clicked. But there was a second minor thing I didn't know about:
As I read in this post the superview of a subview doesn't only have to be userInteractionEnabled but also have a non-transparent backgroundColor. Because my superviews background color was set to [UIColor clearColor] it all didn't work - but setting its backGroundColor to e.g. blackColor solved the whole problem: the bannerView got finally tappable! :)
So, my code is now looking like this:
#synthesize tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
if (!tableView && [self.view isKindOfClass:[UITableView class]]) {
tableView = (UITableView *)self.view;
}
self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
self.tableView.frame = self.view.bounds;
[self.view addSubview:self.tableView];
[self resizeTableToFitBanner];
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:bannerView];
// some other code
}
BannerViewController in Apple's iAdSuite sample code solves this problem very elegantly:
https://developer.apple.com/library/ios/samplecode/iAdSuite/Introduction/Intro.html
I think you should use a container view, and set things up in IB. You can add a tool bar and ADBannerView to the bottom of the view of your navigation controller's root view controller. Fill the rest of the space with a container view - this will give you an embedded view controller automatically. You should delete this one and then drag in a tableViewController and control drag from the container view to the tableViewController to hook up the embed segue.

Switching UIViews without changing the top bar

I'm new to ios programming and I can't figure this out. I have a view-based application with a navigation bar and a "custom" bar under the navigation bar (An image with two UIButtons on it). Under this two bars I have two UIViews that must be shown at the press of the corresponding button on the "custom" bar, but the top bars must remain the same the whole time.
Do you have any ideas how to do this?
You can simply add both the views to your viewControllers subview and use the hidden property of the views to show/hide the correct view.
-(void) viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:view1];
[self.view addSubview:view2];
view1.hidden=YES;
view2.hidden=YES;
}
-(IBAction) btn1Pressed
{
view1.hidden=NO;
view2.hidden=YES;
}
-(IBAction) btn2Pressed
{
view1.hidden=YES;
view2.hidden=NO;
}

Resources