Reputation: 666
i have two Viewcontroller. one with tableview,check button, add button at bottom . i just adjust my tableview up and kept my add button at bottom. when user press my add button it will take to next viewcontroller ( i did these thing via storyboard )
Needed:
I need my add button should be bottom to above my table view.when user scroll down my table view also it should stick at centre of my tableview.i have tried with creating seperate view ,but no use can't do that.Here this is my viewcontroller.m file:
Thanks in advance !
I used storyboard ,so i did iboutlet and synthesis it,
@interface ViewController ()
@property (strong) NSMutableArray *notes;
@end
@implementation ViewController
@synthesize tableView;
@synthesize addButton;
my viewdidload:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.title = @"My Notes";
tableView.dataSource = self;
tableView.delegate = self;
[self.view addSubview:tableView];
}
when my add button presses it will move to another viewcontroller:
- (IBAction)addButtonPressed:(id)sender {
AddNoteViewController *addNoteVC = [AddNoteViewController new];
// to remove unused warning....
#pragma unused (addNoteVC)
}
Like this i need but in centre ....
Upvotes: 0
Views: 664
Reputation: 1377
Since you only want the UIButton
to hover over your UITableView
the solution should be quite easy.
I just created a UIButton
which could the one you using.
in your method where you initialise the UIButton (e.g. viewDidLoad
)
yourBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[yourBtn setImage:[UIImage imageNamed:@"yourIMG"] forState:UIControlStateNormal];
[yourBtn setTitle:@"+" forState:UIControlStateNormal];
yourBtn.frame = CGRectMake(0, self.view.bounds.size.height -150, buttonwidth, buttonheight);
yourBtn.center = CGPointMake(self.view.center.x, self.view.bounds.size.height -155);
[yourBtn addTarget:self action:@selector(addButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:yourBtn];
If this shouldn't be your solution feel free to comment this answer!
To set the width and buttonheight just add the following. Write it above the yourBtn.frame
line!
CGFloat buttonwidth = 57.5;
CGFloat buttonheight = 57.5;
You need to set the segues identifier first in IB. Check: iOS and xcode: how to give a segue a "storyboard id" so that I can programmatically manipulate it
-(IBAction)addButtonPressed:(id)sender {
[self performSegueWithIdentifier:yourSegue sender:self];
}
Cheers
Upvotes: 2
Reputation: 738
I think instead of frame setting in @MasterRazer's answer you should edit or add NSLayoutAttributeCenterX
of your UIButton
in IB. Setting that constraint of your button to 0 would make your button stays in the middle and be a clean and good solution for your problem.
Upvotes: 0