1

我想在以下事情上为您提供帮助。

我有一个 uitableview 列表,其中包含从数据库中获取的内容。现在我想在那里编辑 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;
}
4

2 回答 2

0

我为选择单元格项目创建示例代码,然后显示模型弹出窗口,然后更新该项目,然后按更新,然后该项目更新并显示到表格中,

我认为这是简单易用的应用程序和触发数据库的操作。

所以你可以从这里下载示例代码。

我希望您可以轻松理解并将该代码实施到您的项目中,因此问题可能会得到解决

请下载我为示例代码开发的源代码,您也可以进一步增强此代码。

下载链接在这里。

于 2012-05-18T05:12:54.230 回答
-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

导入“CustomizedCellProductDetails.h”

@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

于 2012-05-18T05:02:38.617 回答