iOS,自定义单元格中特定元素的alertView
我有一个桌子的定制单元,工作正常 我在单元格中显示产品列表,当用户点击“删除”按钮时,我会显示一个确认删除的警报视图 但我需要在警报视图中显示产品名称:iOS,自定义单元格中特定元素的alertView,ios,uitableview,cell,uialertview,Ios,Uitableview,Cell,Uialertview,我有一个桌子的定制单元,工作正常 我在单元格中显示产品列表,当用户点击“删除”按钮时,我会显示一个确认删除的警报视图 但我需要在警报视图中显示产品名称:“您确定要删除XXX吗?” 这里是我的自定义单元格的代码 请注意,deleteCartButtonPressed #import "ShoppingCartProductsCell.h" #import "Product.h" @implementation ShoppingCartProductsCell @synthesize cate
“您确定要删除XXX吗?”
这里是我的自定义单元格的代码
请注意,deleteCartButtonPressed
#import "ShoppingCartProductsCell.h"
#import "Product.h"
@implementation ShoppingCartProductsCell
@synthesize categoryNameLabel = _categoryNameLabel;
@synthesize productNameLabel = _productNameLabel;
@synthesize quantityPicker = _quantityPicker;
@synthesize deleteCartButton = _deleteCartButton;
@synthesize product = _product;
- (void) dealloc {
[_deleteCartButton release];
[_categoryNameLabel release];
[_productNameLabel release];
[_quantityPicker release];
[super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
//self = [super initWithFrame:frame];
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
[self initQuantityPicker];
[self initLabels]; //y picker!
[self initButtons];
}
return self;
}
- (void) initQuantityPicker {
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
self.quantityPicker = [[[BDFDropDownList alloc] initWithFrame:CGRectMake(boundsX+220, 8, 61, 28) popupWidth:90]autorelease];
self.quantityPicker.delegate = self;
for (int i = 1; i<=20; i++) {
[self.quantityPicker addOptionWithName:[NSString stringWithFormat:@"%d",i] value:[NSNumber numberWithInt:i]];
}
[self.contentView addSubview:self.quantityPicker];
}
- (void) initLabels {
self.productNameLabel = [[[UILabel alloc]init] autorelease];
self.productNameLabel.textAlignment = UITextAlignmentLeft;
self.productNameLabel.backgroundColor = [UIColor clearColor];
self.productNameLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
self.productNameLabel.textColor = [UIColor colorWithRed:102/255.0f green:102/255.0f blue:102/255.0f alpha:1];
[self.contentView addSubview:self.productNameLabel];
}
- (void) initButtons {
self.deleteCartButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.deleteCartButton addTarget:self action:@selector(deleteCartButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.deleteCartButton setImage:[UIImage imageNamed:@"deleteCartButton.png"] forState:UIControlStateNormal];
[self.contentView addSubview:self.deleteCartButton]; //Calculations For stage 2
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+10 ,10, 200, 20);
self.productNameLabel.frame = frame;
frame= CGRectMake(boundsX+330 ,8, 30, 29); //310
self.deleteCartButton.frame = frame;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void) setProduct:(Product*)product {
[self setProduct:product withQuantity:0];
}
- (void) setProduct:(Product*)product withQuantity:(NSInteger)quantity {
[_product release];
_product = product;
[_product retain];
self.productNameLabel.text = product.SKU;
self.quantityPicker.delegate = nil;
[self.quantityPicker setSelectedIndex:quantity-1]; //testa
self.quantityPicker.delegate = self;
}
- (void) deleteCartButtonPressed:(id) sender {
NSLog(@"Delete ");
UIAlertView *deleteAlert = [[UIAlertView alloc]initWithTitle:@"Attention" message:@"Are you sure you want to delete this record?" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
[deleteAlert show];
[deleteAlert release];
}
@end
#导入“ShoppingCartProductsCell.h”
#进口“Product.h”
@实现ShoppingCartProductsCell
@合成categoryNameLabel=_categoryNameLabel;
@合成productNameLabel=\u productNameLabel;
@合成量化器=_量化器;
@合成deleteCartButton=\u deleteCartButton;
@合成产物=_产物;
-(无效)解除锁定{
[_DeleteCartButtonRelease];
[_CategoryNameLabelRelease];
[_ProductNameLabelRelease];
[_QuantitypickerRelease];
[super dealoc];
}
-(id)initWithStyle:(UITableViewCellStyle)样式重用标识符:(NSString*)重用标识符
{
//self=[super initWithFrame:frame];
self=[super-initWithStyle:style-reuseIdentifier:reuseIdentifier];
如果(自我){
//初始化代码
[自初始化量化打字机];
[self initLabels];//y picker!
[自启动按钮];
}
回归自我;
}
-(void)initQuantityPicker{
CGRect contentRect=self.contentView.bounds;
CGFloat boundsX=contentRect.origin.x;
self.quantityPicker=[[BDFDropDownList alloc]initWithFrame:CGRectMake(boundsX+220,8,61,28)popuwWidth:90]autorelease];
self.quantityPicker.delegate=self;
对于(inti=1;i字符串文字是您的朋友
- (void) deleteCartButtonPressed:(id) sender {
NSLog(@"Delete ");
UIAlertView *deleteAlert = [[UIAlertView alloc]initWithTitle:@"Attention" message:[NSString stringWithFormat:@"Are you sure you want to delete %@?", [myTableDatasource objectAtIndex:idx]], delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
[deleteAlert show];
[deleteAlert release];
}
最好将其移出您的cell子类,并放入您的数据源和委托中,以便于编写更干净的代码