我想在下面的内容中为您提供帮助。
我有一个uitableview列表,其中包含从DB获取的内容。 现在我想在那里编辑tableviewcell内容。
我的意思是如何让uitableviewcells可编辑?
请让我知道实施上述内容的工作示例链接/参考教程。
感谢您的时间。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary *aDict = [self.mySimpleTemplatesArr objectAtIndex:indexPath.row];
NSString *value = [aDict objectForKey:@"value"];
cell.textLabel.text = value;
// Configure the cell...
return cell;
}
答案 0 :(得分:0)
我为选择单元格项目创建示例代码,然后我显示模型弹出窗口,然后该项目更新,然后按更新然后该项目更新并显示在表格中
我认为这很简单,很容易用到应用程序中并且也可以解雇数据库的操作。
所以你可以从这里下载示例代码。
我希望您可以轻松地将该代码深入到您的项目中,从而解决问题
请下载由我开发的示例代码来源,您也可以更多地增强此代码。
答案 1 :(得分:-1)
以下是一个示例,这是我的代码之一。: -
@interface CustomizedCellProductDetails : UITableViewCell {
UILabel *sNO;
UILabel *abcWine;
UILabel *redWine;
UILabel *two;
UILabel *hundred;
UILabel *fourTwo;
UILabel *twoOne;
UIImageView *imgView;
UILabel *itemNo;
UILabel *itemName;
UILabel *itemDesc;
UILabel *department;
UILabel *qtyAvailable;
UIButton *check;
}
@property (nonatomic , retain) UILabel *sNO;
@property (nonatomic , retain) UILabel *abcWine;
@property (nonatomic , retain) UILabel *redWine;
@property (nonatomic , retain) UILabel *two;
@property (nonatomic , retain) UILabel *hundred;
@property (nonatomic , retain) UILabel *fourTwo;
@property (nonatomic , retain) UILabel *twoOne;
@property (nonatomic , retain) UIImageView *imgView;
@property (nonatomic , retain) UILabel *itemNo;
@property (nonatomic , retain) UILabel *itemName;
@property (nonatomic , retain) UILabel *itemDesc;
@property (nonatomic , retain) UILabel *department;
@property (nonatomic , retain) UILabel *qtyAvailable;
@property (nonatomic , retain) UIButton *check;
-(void) clicked;
@end
@implementation CustomizedCellProductDetails
@synthesize sNO,abcWine,redWine,two,hundred,fourTwo,twoOne,imgView,itemNo,itemName,itemDesc,department,qtyAvailable,check;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
sNO=[[UILabel alloc] init];
abcWine=[[UILabel alloc] init];
redWine=[[UILabel alloc] init];
two=[[UILabel alloc] init];
hundred=[[UILabel alloc] init];
fourTwo=[[UILabel alloc] init];
twoOne=[[UILabel alloc] init];
imgView=[[UIImageView alloc] init];
itemNo=[[UILabel alloc] init];
itemName=[[UILabel alloc] init];
itemDesc=[[UILabel alloc] init];
department=[[UILabel alloc]init];
qtyAvailable=[[UILabel alloc] init];
check=[UIButton buttonWithType:UIButtonTypeCustom];
[check addTarget:self action:@selector(clicked) forControlEvents:UIControlEventTouchUpInside];
[check setTitle:@"Check" forState:UIControlStateNormal];
[self.contentView addSubview:sNO];
[self.contentView addSubview:abcWine];
[self.contentView addSubview:redWine];
[self.contentView addSubview:two];
[self.contentView addSubview:hundred];
[self.contentView addSubview:fourTwo];
[self.contentView addSubview:twoOne];
[self.contentView addSubview:itemNo];
[self.contentView addSubview:itemName];
[self.contentView addSubview:itemDesc];
[self.contentView addSubview:department];
[self.contentView addSubview:qtyAvailable];
[self.contentView addSubview:check];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame=CGRectMake(boundsX+10, 0, 50, 40);
sNO.frame = frame;
frame= CGRectMake(boundsX+70 ,0, 150, 40);
abcWine.frame = frame;
frame= CGRectMake(boundsX+230 ,0, 150, 40);
redWine.frame = frame;
frame= CGRectMake(boundsX+390 ,0, 50, 40);
two.frame = frame;
frame= CGRectMake(boundsX+450 ,0, 50, 40);
hundred.frame = frame;
frame= CGRectMake(boundsX+510 ,0, 50, 40);
fourTwo.frame = frame;
frame= CGRectMake(boundsX+570 ,0, 50, 40);
twoOne.frame = frame;
/************************ ***********************/
frame= CGRectMake(boundsX+10 ,50, 100, 200);
imgView.frame = frame;
}
-(void) clicked
{
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state.
}
- (void)dealloc {
[super dealloc];
}
@end
只需在cellforRowAtIndexPath中使用此类的实例,并根据需要对其进行修改。要在运行时更改值,请访问属性。
您可以通过以下方式在tableview中实现自定义cemm: -
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
CustomizedCellProductDetails *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomizedCellProductDetails alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.sNO.text=@"2255";
cell.abcWine.text=@"ABCWine";
cell.redWine.text=@"REDWine";
cell.two.text=@"2";
cell.hundred.text=@"100";
cell.fourTwo.text=@"42";
cell.twoOne.text=@"21";
[cell.imgView setImage:[UIImage imageNamed:@"wine.png"]];
cell.itemNo.text=@"Item No 2255";
cell.itemName.text=@"Item Name ABCWine";
cell.itemDesc.text=@"Item Description This is the best wine";
cell.qtyAvailable.text=@"Quantity Available 2";
// Configure the cell...
return cell;
}
更改单元格的高度: -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 300;
}
不要使用300而是将单元格框架的高度设为cell.frame.size.height