This tableview cell code works, i.e. displays my array of session strings:
.................................
This code does not work, i.e. blank cells except last one ... why?:
Code:
@interface OrderFormController : UITableViewController <UITextFieldDelegate>
@property (nonatomic, retain) NSMutableArray *tableData;
@property (nonatomic, retain) NSMutableArray *sessions;
@property (nonatomic, retain) NSString *individualSession;
@property (nonatomic, retain) UITableViewCell *cell;
@end
@implementation OrderFormController
@synthesize tableData = _tableData;
@synthesize sessions = _sessions;
@synthesize individualSession = _individualSession;
@synthesize cell = _cell;
- (void)viewDidLoad {
[super viewDidLoad];
self.tableData = [[NSMutableArray alloc]initWithArray:self.sessions];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
self.cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (self.cell == nil) {
self.cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
self.individualSession = [self.tableData objectAtIndex:indexPath.row];
UITextField *cellText = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 768, 31)]; //cellText is local to this function
cellText.text = self.individualSession;
[self.cell.contentView addSubview:cellText];
return self.cell;
}
@end
.................................
This code does not work, i.e. blank cells except last one ... why?:
Code:
@interface OrderFormController : UITableViewController <UITextFieldDelegate>
@property (nonatomic, retain) NSMutableArray *tableData;
@property (nonatomic, retain) NSMutableArray *sessions;
@property (nonatomic, retain) NSString *individualSession;
@property (nonatomic, retain) UITableViewCell *cell;
@property (nonatomic, retain) UITextField *cellTxt;
@end
@implementation OrderFormController
@synthesize tableData = _tableData;
@synthesize sessions = _sessions;
@synthesize individualSession = _individualSession;
@synthesize cell = _cell;
@synthesize cellTxt = _cellTxt;
- (void)viewDidLoad {
[super viewDidLoad];
self.tableData = [[NSMutableArray alloc]initWithArray:self.sessions];
self.cellTxt = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 768, 31)];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
self.cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (self.cell == nil) {
self.cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
self.individualSession = [self.tableData objectAtIndex:indexPath.row];
self.cellTxt.text = self.individualSession; //cellTxt is global to this class
[self.cell.contentView addSubview:self.cellTxt];
return self.cell;
}
@end
Last edited: