我有一个视图,其中包含用户动态添加的标签。如果用户想编辑任何标签,他们按下一个按钮,所有标签都会通过删除按钮和移动按钮突出显示。(编辑是我稍后会跨越的另一座桥)。
我的问题是:打开和关闭按钮的最佳方法是什么?我有一种打开按钮的方法……但我不知道在完成编辑时如何关闭它们。我是否需要标记我的按钮然后“隐藏它们”?还是我完全删除它们?我如何解析所有打开的按钮,然后将它们关闭。我是否也需要将它们放入数组中?标签上标有唯一的数字,所以我知道哪个标签是哪个。
有什么想法吗?指导?如果我做错了,请告诉我。
这是我有的几种方法:
- (void) showEditableText {
// Parse the array of labels
if(textArray.count > 0){
for(UILabel *label in textArray){
//Add Delete Button
UIImage * delButtonImage = [UIImage imageNamed:@"GUI_Delete.png"];
UIButton * delThisButton = [[UIButton alloc] initWithFrame:CGRectMake(label.frame.origin.x - delButtonImage.size.width, label.frame.origin.y - delButtonImage.size.height, delButtonImage.size.width, delButtonImage.size.height)];
[delThisButton setBackgroundImage:delButtonImage forState:UIControlStateNormal];
[delThisButton addTarget:self action:@selector(deleteThisLabel:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:delThisButton];
//Add a move button
UIImage * moveButtonImage = [UIImage imageNamed:@"GUI_Move.png"];
UIButton * moveThisButton = [[UIButton alloc] initWithFrame:CGRectMake((label.frame.origin.x + label.frame.size.width + moveButtonImage.size.width), label.frame.origin.y - moveButtonImage.size.height, moveButtonImage.size.width, moveButtonImage.size.height)];
[moveThisButton setBackgroundImage:moveButtonImage forState:UIControlStateNormal];
[moveThisButton addTarget:self action:@selector(moveThisLabel:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:moveThisButton];
//Make the text highlighed
label.highlighted = YES;
label.backgroundColor = [UIColor colorWithRed:203/255.0f green:230/255.0f blue:239/255.0f alpha:1];
label.highlightedTextColor = [UIColor redColor];
}
}
}
- (void) doneEditingText {
if(textArray.count > 0){
for(UILabel *label in textArray){
//THIS IS WHERE I AM STUCK? WHAT DO I DO?
label.highlighted = NO;
label.backgroundColor = [UIColor clearColor];
}
}
}