Reputation: 4301
I am trying to create a UITableView with subview and i using a tutorial i have found. However, i am not able to display any data on the table, no error.
Would like to ask if someone could look at the code and give me a hint how to get this to work?
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
CGRect CellFrame = CGRectMake(0, 0, 300, 60);
CGRect Label1Frame = CGRectMake(10, 10, 290, 25);
CGRect Label2Frame = CGRectMake(10, 33, 290, 25);
UILabel *lblTemp;
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
//Initialize Label with tag 1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
[cell.contentView addSubview:lblTemp];
[lblTemp release];
//Initialize Label with tag 2.
lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
lblTemp.tag = 2;
lblTemp.font = [UIFont boldSystemFontOfSize:12];
lblTemp.textColor = [UIColor lightGrayColor];
[cell.contentView addSubview:lblTemp];
[lblTemp release];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
cell = [self getCellContentView:CellIdentifier];
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
//First get the dictionary object
// NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [[NSArray alloc]initWithObjects: @"One", @"Two", @"Three", nil];
NSString *cellValue = [array objectAtIndex:indexPath.row];
lblTemp1.text = cellValue;
lblTemp2.text = @"Sub Value";
[cellValue release];
return cell;
}
Upvotes: 0
Views: 719
Reputation: 20569
Very basic question, but have you made sure to set the number of rows and sections that need to be displayed in the table view? If you set a breakpoint, can you see the tableView:cellForRowAtIndexPath:
being called?
Upvotes: 2