I need to align the text in the cell to right.
but even when i set to right the text is align to left as show in the screen shot any idea why is this strange behaviour of the cell
cell.textLabel.textAlignment = NSTextAlignmentRight;
cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
After reading related questions and answers on stackoverflow I could not find one solving my problem

No can not change the frame of titleLabel of Cell. Instead you can add custom label to contentView of cell.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellIdentifier = @"Cell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
UILabel *lblStatus = [[UILabel alloc] initWithFrame:CGRectMake(12, 8, 175, 15)];
lblStatus.backgroundColor = [UIColor clearColor];
[lblStatus setTag:101];
[cell.contentView addSubview:lblStatus];
}
UILabel *lbl1 = (UILabel *)[cell.contentView viewWithTag:101];
lbl1.text=@"set text";
}
return cell;
}
You can also achieve this by prototype cell. here is a good tutorial of prototype cell.
your coding is fine , u need to change the cell.textLabel. frame size to right side in my choice is use custom label
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With