Iphone 对子表视图使用导航栏中的“编辑”按钮
嗨,我的视图中有一个Iphone 对子表视图使用导航栏中的“编辑”按钮,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,嗨,我的视图中有一个tableView。但我希望导航栏中的编辑对tableView起作用。你能告诉我怎么做吗 我为主视图设置了导航栏,并设置了tableView 我制作了一个创建导航栏的方法: - (UINavigationBar *)createNavigationBar { UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:@"Task Manager"]; UINavigationBar *new = [[U
tableView
。但我希望导航栏中的编辑对tableView起作用。你能告诉我怎么做吗
我为主视图设置了导航栏,并设置了tableView
我制作了一个创建导航栏的方法:
- (UINavigationBar *)createNavigationBar
{
UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:@"Task Manager"];
UINavigationBar *new = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:nil];
title.leftBarButtonItem = addButton;
[new pushNavigationItem:title animated:YES];
UIColor *color = UIColorFromRGB(0xff8c00); // Dark orange
new.tintColor = color;
return new;
}
我有
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
设置好了
当我点击主导航栏中的编辑按钮时,我基本上需要在子表视图中显示红色圆圈
如果我不清楚,我很抱歉。如果你需要任何澄清,请问我
谢谢!:) 您只需将tableView设置为编辑模式即可。。你可以这样做
[yourTableView setEditing:YES animated:YES];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editPressed)];
您将在按钮操作中输入此代码。。所以你需要把你的代码改成这样
[yourTableView setEditing:YES animated:YES];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editPressed)];
您应该有一个BOOL变量来存储当前编辑状态,并有一个函数(
addTarget
)到编辑按钮,该函数将根据此变量将表格置于编辑模式,如下所示:
-(IBAction) editWasPressed:(id)sender
{
editMode = ! editMode;
if(editMode)
{
[table setEditing:YES animated:YES];
}
else
{
[table setEditing:NO animated:YES];
}
}
您应该将名为new
的变量重命名为其他变量 在你的视图中画这行willapear:
然后在编辑中按下:方法
[my_table setEditing:!my_table.editing animated:YES];
希望这能帮助你