UIButton标签覆盖
问题描述:
你如何确保UIButton标签不被前面的标签覆盖?UIButton标签覆盖
例如:
(IBAction)addButton:(id)sender {
if (buttoncount == 2) return
buttoncount++
UIButton *newButton
...
// Should I change this to setTag?
newButton.tag = buttoncount;
// This line doesn't seem to work
newbutton.tag = newButtonCount NSInteger(buttoncount);
...
[self.view addSubview:newButton];
}
提前
答
由于这是不客观的,C:
newbutton.tag = newButtonCount NSInteger(buttoncount);
删除线,并如预期,因为buttonCount递增您的代码应工作每次添加一个按钮。第一个按钮将被标记为1,第二个按钮将被标记为2,之后看起来您的代码将阻止两个以上的按钮。
你究竟期待这段代码做什么?标签是UIView用于查找或未来再次识别它的属性。你可以请求一个视图来查找-viewWithTag:它返回其具有指定标签的子视图。 – 2010-08-11 12:51:03
对不起,您是对的。我用错误的方式问了这个问题。这与“http://*.com/questions/3421940/one-uibutton-at-a-time”有关我实际上试图用newbutton.tag = newButtonCount NSInteger(buttoncount)替换newButton.tag来停止newButton .tag之前生成的按钮不会被下一个生成的按钮覆盖。希望有所帮助。 – nepfable 2010-08-11 18:09:44
标题应该说覆盖*:D – 2010-08-11 19:56:39