Reputation: 435
i want to have two data on each row on my tableview. Something like Recent Call (on the left the name, on the right the day)
this is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
//cell.selectionStyle = UITableViewCellStyleValue1 ;
}
// Configure the cell.
NSDictionary *dictionary = [listaOggetti objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"Elementi"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
NSArray *array1 = [dictionary objectForKey:@"Tipo"];
NSString *cellDetail = [array1 objectAtIndex:indexPath.row];
if ([indexPath row] == 0){
cell.textLabel.text = cellValue;
cell.textAlignment = UITextAlignmentCenter;
cell.backgroundColor = [UIColor blueColor];
cell.font = [UIFont systemFontOfSize:13];
} else {
cell.textLabel.text = cellDetail;
cell.detailTextLabel.text = cellValue;
}
return cell;
}
i've try to use different style on
initWithStyle
without any result (only show my detailtext on the right). In NSLOG i see the right value of cellDetail.
{
Elementi = (
"Chiamate e Videochiamate Nazionali",
"08m:43s",
"1h:31m:17s",
"1h:40m:00s"
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
},
{
Elementi = (
"SMS e MMS Nazionali",
21,
29,
50
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
},
{
Elementi = (
"Traffico Dati FMM",
"69.95 MB",
"954.05 MB",
"1024.00 MB"
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
},
{
Elementi = (
Skype,
"00m:00s",
"3h:20m:00s",
"3h:20m:00s"
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
},
{
Elementi = (
"WWW3, Yahoo!, Google, eBay e altri servizi",
"0.00 MB",
"100.00 MB",
"100.00 MB"
);
},
{
Tipo = (
Effettuato,
Rimanente,
Totale
);
}
)
my goal is to obtain cells like this:
Upvotes: 0
Views: 692
Reputation: 435
Thank's to all, my code is ok, the fault is on the second array. Solved in this way:
NSDictionary *dictionary1 = [listaDettaglioOggetti objectAtIndex:indexPath.section];
NSArray *array1 = [dictionary1 objectForKey:@"Tipo"];
NSString *cellDetail = [array1 objectAtIndex:indexPath.row];
The last question:
i would modify the first row on each section (modify font size, color, aligment). I've think something like this:
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
if (sectionRows == 0){
cell.textLabel.text = cellDetail;
cell.detailTextLabel.textAlignment = UITextAlignmentCenter;
cell.detailTextLabel.backgroundColor = [UIColor blueColor];
cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
} else {
cell.textLabel.text = cellDetail;
cell.detailTextLabel.text = cellValue;
}
but this don't make the magic:D Please let me know if it's better to open another topic or we can continue here.
Upvotes: 0
Reputation: 33345
I believe you need to initialize the cell like this, you are using the incorrect style when initializing the cell
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
Upvotes: 1
Reputation: 2720
I would consider creating a custom Cell, its easy to do and it really looks the ticket if done well.
Otherwise, Your code looks ok, check that your labels have been alloc'd (not nil).
On a side note, how many items do you have in your dataset? I only ask because if its only 1, you never set detailTextLabel.
Upvotes: 1