在自定义的uitableviewcell中保留数据/文本

时间:2011-06-24 13:39:13

标签: iphone uitableview

WeekViewTableCell.h:

 @interface WeekViewTableCell : UITableViewCell {

    UILabel         *textlabel;
    UILabel         *taxdetails;
    UITextField     *dayNumberInWeek;
    UITextField     *commentsForWeek;
}

    @property (nonatomic ,retain) IBOutlet UILabel      *textlabel;
    @property (nonatomic, retain) IBOutlet UILabel      *taxdetails;
    @property (nonatomic, retain) IBOutlet UITextField  *dayNumberInWeek;
    @property (nonatomic, retain) IBOutlet UITextField  *commentsForWeek;


@end

WeekViewTableCell.m:

import "WeekViewTableCell.h"


    @implementation WeekViewTableCell
    @synthesize textlabel;
    @synthesize taxdetails;
    @synthesize dayNumberInWeek;
    @synthesize commentsForWeek;

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code.

    }
    return self;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state.
}


- (void)dealloc {
    [textlabel release];
    [taxdetails release];
    [dayNumberInWeek release];
    [commentsForWeek release];
    [super dealloc];
}

@end

DataSource:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *cellIdentifier = @"WeekViewCell";  
WeekViewTableCell *cell = (WeekViewTableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (!cell) {
    [self.appCellNib instantiateWithOwner:self options:nil];

    cell = weekTableViewCell;       
    self.weekTableViewCell = nil;
}

        if (indexPath.section == 0) {

                cell.dayNumberInWeek.hidden = YES;
                cell.commentsForWeek.hidden = YES;
                self.tableView.rowHeight = CELL_ROW_HEIGHT;
                cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
                cell.taxdetails.tag = 1;

                if (indexPath.row == 0)
                {   
                    cell.textlabel.text = @"Week Day";

                    if (isDoneSelected == YES) 
                        cell.taxdetails.text = [self dateFormatStyle:[uniqueDays objectAtIndex:6]];

                    else 
                        cell.taxdetails.text = [DaysOfCurrentWeek newDateString:[DaysOfCurrentWeek getDayOfCurrentWeek:_kSaturday]];
                }
            }
}

我想在视图中将文本/数据保存在自定义uitableviewcell的文本字段中,该视图中还有3个部分。每次向上/向下滚动数据/文本消失,我都知道问题所在。 但是,如果有人发布了一些非常有用的示例/示例代码,那就好了,因为我现在很长时间都在苦苦挣扎。

感谢。

1 个答案:

答案 0 :(得分:0)

尝试使用cellForRowAtIndexPath:功能中的以下代码。

NSString *cellIdentifier = [NSString stringWithFormat:@"WeekViewCell_%d_%d",indexPath.section,indexPath.row];  
WeekViewTableCell *cell = (WeekViewTableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
相关问题