persist data/text in a custom uitableviewcell
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:reuseIde开发者_运维知识库ntifier];
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]];
}
}
}
I want to persist text/data in textfields in a custom uitableviewcell in a view which has again 3 sections. Every time scroll up/down the data/text disappears, I know the the problem. But again if someone kindly post some sample/example code that would be really helpful, as am struggling now for a long time.
thanks.
Try with below code in your cellForRowAtIndexPath:
function.
NSString *cellIdentifier = [NSString stringWithFormat:@"WeekViewCell_%d_%d",indexPath.section,indexPath.row];
WeekViewTableCell *cell = (WeekViewTableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
精彩评论