我正在尝试使用添加和删除动态添加两个按钮。单击添加按钮时,应将标签更改为删除,反之亦然。
我可以动态执行添加或删除按钮的操作,但是表视图的状态正在改变它始终保持添加按钮..
感谢名单
让我在这里添加我的代码。
I am creating UI button and adding label like in for loop.Is this right approach?
UIButton *btn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
btn.frame = CGRectMake(230, 25, 73, 40) ;
btn.tag = indexPath.row+1;
btn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
for (int i=0;i<[myarrayone count]; i++)
{
for (int j=0; j<[[appDelegate AddingCartArray] count]; j++)
{
if([myarrayone objectAtIndex:i] == [[appDelegate AddingCartArray] objectAtIndex:j])
{
[btn setBackgroundImage:[UIImage imageNamed:@"RemovetoCart.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(Remove:) forControlEvents:UIControlEventTouchUpInside];
}
else {
[btn setBackgroundImage:[UIImage imageNamed:@"adtoCart.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(addCartClicked:) forControlEvents:UIControlEventTouchUpInside];
}
答案 0 :(得分:0)
在你的按钮点击方法中也重新加载tableView
[myTableView reloadData];