gpt4 book ai didi

iphone - 在 ViewController 中启用编辑模式

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:14:11 27 4
gpt4 key购买 nike

我是 iOS 开发的新手,我想在 View 中显示用户配置文件,同时我想让用户可以通过点击 UINavigationBar 上的“编辑”按钮来编辑他的配置文件,例如Apple 网站上显示:Enabling Edit Mode in a View Controller

我试图找到一个解释所有这些的教程,但我没有找到任何东西。有人可以通过给我一个教程链接或示例代码来帮助我吗?

PS:我正在使用 Storyboard。

非常感谢!

最佳答案

Herehere是 UITableview 的几个例子

概念是一样的。您添加一个 UIBarButtonItem 并更改 tableView 的当前模式和 buttonItem 的状态(文本)以显示编辑破折号和其他内容(如果您愿意)。

这是一个简单的编辑模式按钮,按下可将 tableView 发送到编辑模式,以便轻松删除。你也可以

- (IBAction)editPressed:(id)sender
{
// If the tableView is editing, change the barButton title to Edit and change the style
if (_theTableView.isEditing) {
UIBarButtonItem *newButton = [[UIBarButtonItem alloc]initWithTitle:@"Edit" style:UIBarButtonSystemItemDone target:self action:@selector(editPressed:)];
self.navigationItem.rightBarButtonItem = newButton;
_buttonEdit = newButton;
[_theTableView setEditing:NO animated:YES];
}
// Else change it to Done style
else {
UIBarButtonItem *newButton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonSystemItemEdit target:self action:@selector(editPressed:)];
self.navigationItem.rightBarButtonItem = newButton;
_buttonEdit = newButton;
[_theTableView setEditing:YES animated:YES];
}
}


-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];

// You could do other things in here based on whether editing is true or not
}

关于iphone - 在 ViewController 中启用编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16426490/

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