我目前正在尝试创建一种 tasktracker.. 以下代码当前有效,但我需要它来删除带有按钮标签的行.. 换句话说。
当按下标签为0的按钮时,删除标签为0的行
我所有的尝试都失败了,所以我把它带给专家。
- (void)buttonPressedAction:(id)sender
{
UIButton *button = (UIButton *)sender;
NSInteger *row = button.tag;
NSString *cleanedUp = [NSString stringWithFormat:@"%d", row];
if(button.titleLabel.text == @"Unchecked"){
[button setTitle:@"Checked" forState:UIControlStateNormal];
}
else{
[button setTitle:@"Unchecked" forState:UIControlStateNormal];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:button.titleLabel.text
message:cleanedUp
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
最佳答案
UITableView
有 built-in capabilities to allow the deletion的行。这可能更适合您想要完成的目标。这是一个 example .
要使用自定义按钮,您需要使用 beginUpdates
和 endUpdates
来修改您的表格 View 动画。
NSInteger row = button.tag;
[tableView beginUpdates];
//make sure you remove the row from your datasource
//as well or an exception will be raised
[self.datasource removeObjectAtIndex:row]
[deleteRowsAtIndexPaths:[NSIndexPath indexPathForRow:row inSection:0]
withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
关于ios - 按标签删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7985592/