gpt4 book ai didi

ios - 如何在我的 UITableview 底部设置(制作)一个 UIButton?

转载 作者:行者123 更新时间:2023-11-28 21:40:19 25 4
gpt4 key购买 nike

enter image description here我有两个 View Controller 。一个带有tableview,检查按钮,在底部添加按钮。我只是向上调整我的 tableview 并将我的添加按钮保留在底部。当用户按下我的添加按钮时,它将转到下一个 View Controller (我通过 Storyboard做了这些事情)

需要:

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

提前致谢!

我用了 Storyboard,所以我做了 iboutlet 并合成了它,

@interface ViewController ()



@property (strong) NSMutableArray *notes;
@end

@implementation ViewController
@synthesize tableView;
@synthesize addButton;

我的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];
}

当我按下添加按钮时,它将移动到另一个 View Controller :

- (IBAction)addButtonPressed:(id)sender {
AddNoteViewController *addNoteVC = [AddNoteViewController new];




// to remove unused warning....
#pragma unused (addNoteVC)

}

像这样我需要但在中心....

最佳答案

因为您只希望 UIButton 悬停在您的 UITableView 上,所以解决方案应该很简单。

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

在您初始化 UIButton 的方法中(例如 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];

如果这不是您的解决方案,请随时评论此答案!

编辑

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

CGFloat buttonwidth = 57.5;
CGFloat buttonheight = 57.5;

编辑 2.0

您需要先在 IB 中设置 segues 标识符。检查: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];
}

干杯

关于ios - 如何在我的 UITableview 底部设置(制作)一个 UIButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32406586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com