我正在以编程方式创建一个剖面视图,并且我还有一个UIButton
“delete”也以编程方式分配。但是,按下按钮时,我想从我的tableview中删除该部分。我应该如何去做这件事?我想从一个UITableView中删除一个部分,当它内部按下“删除”按钮时
下面是创建节头视图代码:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* customView;
if (Cart.myOrderSummaryRow == 0)
{
// create the parent view that will hold header Label
customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.00)];
customView.backgroundColor = [UIColor grayColor];
//food item label
UILabel * _headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_headerLabel.backgroundColor = [UIColor clearColor];
_headerLabel.opaque = YES;
_headerLabel.textColor = [UIColor blackColor];
//_headerLabel.highlightedTextColor = [UIColor whiteColor];
_headerLabel.font = [UIFont boldSystemFontOfSize:14];
_headerLabel.frame = CGRectMake(40.0, 0.0, 300.0, 44.0);
NSMutableString *header = [[[NSMutableString alloc] initWithCapacity:20] autorelease];
FoodItem *tmpFoodItem = [Cart.foodItemsArray objectAtIndex:section];
[header appendString:tmpFoodItem.foodName];
_headerLabel.text = header;
[customView addSubview:_headerLabel];
//price label
UILabel * _priceLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_priceLabel.backgroundColor = [UIColor clearColor];
_priceLabel.opaque = YES;
_priceLabel.textColor = [UIColor blackColor];
//_headerLabel.highlightedTextColor = [UIColor whiteColor];
_priceLabel.font = [UIFont boldSystemFontOfSize:14];
_priceLabel.frame = CGRectMake(200.0, 0.0, 300.0, 44.0);
NSMutableString *price = [[[NSMutableString alloc] initWithCapacity:20] autorelease];
[price appendString:@"$"];
[price appendString:tmpFoodItem.foodPrice];
_priceLabel.text = price;
[customView addSubview:_priceLabel];
//delete button
UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
deleteButton.frame = CGRectMake(260.0, 10, 40.0, 20.0); // x,y,width,height
[deleteButton setTitle:@"-" forState:UIControlStateNormal];
[deleteButton addTarget:self
action:@selector(foodDeleteButtonPressed:)
forControlEvents:UIControlEventTouchDown];
[customView addSubview:deleteButton];
} else {
customView = nil;
}
return customView;
}
下面是UITableView
的样子 -
正如你所看到的部分是灰色和有部分内的按钮用于删除节本身。非突出部分是行。这些部分对应于食品,行对应于侧面项目。段和行有不同的删除按钮。