Iphone 在自定义uitableviewcell中保留数据/文本
WeekViewTableCell.h:Iphone 在自定义uitableviewcell中保留数据/文本,iphone,uitableview,Iphone,Uitableview,WeekViewTableCell.h: @interface WeekViewTableCell : UITableViewCell { UILabel *textlabel; UILabel *taxdetails; UITextField *dayNumberInWeek; UITextField *commentsForWeek; } @property (nonatomic ,retain)
@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
数据源:
- (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中的textfields中,该视图又有3个部分。每次上下滚动数据/文本消失时,我都知道问题所在。
但是,如果有人愿意发布一些示例/示例代码,这将非常有帮助,因为我已经挣扎了很长一段时间
谢谢。在您的
cellforrowatinexpath:
函数中尝试以下代码
NSString *cellIdentifier = [NSString stringWithFormat:@"WeekViewCell_%d_%d",indexPath.section,indexPath.row];
WeekViewTableCell *cell = (WeekViewTableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
这是我典型的自定义uitableviewcell类,其属性是通过位错误读取声明的。尽管我创建了一个singleton类并将数据保存在该类中,并且在每次滚动后尝试更新textfield文本/数据时,textfield从不填充数据。如果您仍然有相同的问题,请告诉我我我是否更改了它,但我还是遇到了同样的问题。