Reputation: 9
I have to align text in table cell to right and left.I have used two plist in my application according to plist selection I have to align my text in table cell.
I try following code for that
if ([app.currentPlist isEqualToString:@"Accounting.plist"]) {
cell.textAlignment=UITextAlignmentLeft;
} else {
cell.textAlignment=UITextAlignmentRight;
}
Upvotes: 0
Views: 8465
Reputation: 91
UITextAlignmentRight
is deprecated, use NSTextAlignmentLeft
instead
So, the code will be -
cell.textLabel.textAlignment = NSTextAlignmentLeft;
Upvotes: 2
Reputation: 2628
In swift it is
cell.textLabel.textAlignment = NSTextAlignment.Right
Upvotes: 1
Reputation: 13361
UITableViewCell
doesn't have a textAlignment
property. You have to set it on the cell's text label:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"Something";
if([app.currentPlist isEqualToString:@"Accounting.plist"])
{
cell.textLabel.textAlignment=UITextAlignmentLeft;
}
else
{
cell.textLabel.textAlignment=UITextAlignmentRight;
}
return cell;
}
Upvotes: 2