Hi everyone,
I am trying something that seemed simple enough when I started, but has quickly complicated. I am simply trying to use a UILabel for a custom view in the accesoryView of a UITableViewCell.
I set everything up like this in my data source:
Based on examples I've seen in google searches, everybody seems to be doing this type of setup in viewDidLoad method, but since my datasource is a custom class, I don't have that method available. I've also seen people initialize a UILabel using initWithFrame:frame, but I have no idea where the "frame" object is supposed to come from. I've also seen people add the view to the contentView using the addView: method. I chose this approach since it's documented in Apple's docs on TableViews. Simply assign a new view to the accessoryView property, and there it is. However, when I run my app with this code, no UILabels are added to the right of my cells. Also, if I uncomment the UIFont lines, the app crashes.
Can anyone tell me what I am doing wrong? Any help will be greatly appreciated.
I am trying something that seemed simple enough when I started, but has quickly complicated. I am simply trying to use a UILabel for a custom view in the accesoryView of a UITableViewCell.
I set everything up like this in my data source:
Code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
Descuento *desc = [descuentos objectAtIndex:indexPath.row];
cell.textLabel.text = [desc getAsFinalCalculatedValue:[salario_bruto floatValue]];
//setea accesoryview
UILabel *label = [[UILabel alloc] init];
UIColor *color = [UIColor colorWithRed:0.0f green:0.0f blue:1.0f alpha:1.0f];
//UIFont *font = [[UIFont alloc] fontWithSize:70.f];
label.textColor=color;
//label.font = font;
label.text = [desc.percent stringValue];
cell.accessoryView=label;
return cell;
}
Based on examples I've seen in google searches, everybody seems to be doing this type of setup in viewDidLoad method, but since my datasource is a custom class, I don't have that method available. I've also seen people initialize a UILabel using initWithFrame:frame, but I have no idea where the "frame" object is supposed to come from. I've also seen people add the view to the contentView using the addView: method. I chose this approach since it's documented in Apple's docs on TableViews. Simply assign a new view to the accessoryView property, and there it is. However, when I run my app with this code, no UILabels are added to the right of my cells. Also, if I uncomment the UIFont lines, the app crashes.
Can anyone tell me what I am doing wrong? Any help will be greatly appreciated.