如何在我的 UITableview 底部设置(制作)一个 UIButton? [英] how to set (make) a UIButton at bottom of my UITableview?

查看:47
本文介绍了如何在我的 UITableview 底部设置(制作)一个 UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个视图控制器.一个带有 tableview,检查按钮,在底部添加按钮.我只是调整我的 tableview 并将我的添加按钮保留在底部.当用户按下我的添加按钮时,它将转到下一个视图控制器(我通过故事板做了这些事情)

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 )

需要:

我需要我的添加按钮应该在我的表格视图的底部到上方.当用户向下滚动我的表格视图时,它也应该贴在我的表格视图的中心.我尝试过创建单独的视图,但没有用不能这样做.这是我的 viewcontroller.m 文件:

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:

提前致谢!

我使用了故事板,所以我做了 iboutlet 并合成了它,

I used storyboard ,so i did iboutlet and synthesis it,

@interface ViewController ()



@property (strong) NSMutableArray *notes;
@end

@implementation ViewController
@synthesize tableView;
@synthesize addButton;

我的视图加载:

- (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 ....

推荐答案

由于您只希望 UIButton 悬停在您的 UITableView 上解决方案应该很简单.

Since you only want the UIButton to hover over your UITableView the solution should be quite easy.

我刚刚创建了一个 UIButton,您可以使用它.

I just created a UIButton which could the one you using.

在您初始化 UIButton 的方法中(例如 viewDidLoad)

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!

要设置宽度和按钮高度,只需添加以下内容.将其写在 yourBtn.frame 行上方!

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;

编辑 2.0

您需要先在 IB 中设置 segues 标识符.检查:iOS 和 xcode:如何给 segue 一个故事板 id";这样我就可以以编程方式操作它

-(IBAction)addButtonPressed:(id)sender {
    [self performSegueWithIdentifier:yourSegue sender:self];
}

干杯

这篇关于如何在我的 UITableview 底部设置(制作)一个 UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆