Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6578841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:49:22+00:00 2026-05-25T15:49:22+00:00

I am trying to understand how to left justify the entries in a UITableView.

  • 0

I am trying to understand how to left justify the entries in a UITableView. I was looking at the source code from chapter 8 Wei-Meng Lee’s book “Beginning iOS 4 Application Development (WROX)”.

The running app looks like this

The Source looks like this:

TableViewExample.h

//
//  TableViewExampleViewController.h
//  TableViewExample
//
//  Created by Wei-Meng Lee on 5/18/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TableViewExampleViewController : UIViewController 
    <UITableViewDataSource, UITableViewDelegate> {      

}

@end

TableViewExample.m

//
//  TableViewExampleViewController.m
//  TableViewExample
//
//  Created by Wei-Meng Lee on 5/18/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "TableViewExampleViewController.h"

@implementation TableViewExampleViewController

NSMutableArray *listOfMovies;

//---insert individual row into the table view--- 
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell";

    //---try to get a reusable cell--- 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    //---create new cell if no reusable cell is available--- 
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                       reuseIdentifier:CellIdentifier] autorelease];
    }

    //---set the text to display for the cell--- 
    NSString *cellValue = [listOfMovies objectAtIndex:indexPath.row]; 
    cell.textLabel.text = cellValue;

    //---display an image---
    UIImage *image = [UIImage imageNamed:@"apple.jpeg"];
    cell.imageView.image = image;   

    return cell;    
}

//---set the number of rows in the table view---
- (NSInteger)tableView:(UITableView *)tableView 
 numberOfRowsInSection:(NSInteger)section {
    return [listOfMovies count];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    //---initialize the array--- 
    listOfMovies = [[NSMutableArray alloc] init];

    //---add items--- 
    [listOfMovies addObject:@"Training Day"]; 
    [listOfMovies addObject:@"Remember the Titans"]; 
    [listOfMovies addObject:@"John Q."]; 
    [listOfMovies addObject:@"The Bone Collector"];
    [listOfMovies addObject:@"Ricochet"]; 
    [listOfMovies addObject:@"The Siege"]; 
    [listOfMovies addObject:@"Malcolm X"]; 
    [listOfMovies addObject:@"Antwone Fisher"];
    [listOfMovies addObject:@"Courage Under Fire"];
    [listOfMovies addObject:@"He Got Game"]; 
    [listOfMovies addObject:@"The Pelican Brief"]; 
    [listOfMovies addObject:@"Glory"]; 
    [listOfMovies addObject:@"The Preacher's Wife"];
    [super viewDidLoad];
}

- (NSString *)tableView:(UITableView *)tableView 
titleForHeaderInSection:(NSInteger)section{ 
    //---display "Movie List" as the header---
    return @"Movie List";
}

- (NSString *)tableView:(UITableView *)tableView 
titleForFooterInSection:(NSInteger)section {
    //---display "by Denzel Washington" as the footer--- 
    return @"by Denzel Washington";
}

- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *movieSelected = [listOfMovies objectAtIndex:indexPath.row];
    NSString *msg = [NSString stringWithFormat:@"You have selected %@", movieSelected];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Movie selected" 
                                                    message:msg
                                                   delegate:self 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles:nil];
    [alert show]; 
    [alert release]; 
}

- (NSInteger)tableView:(UITableView *)tableView 
indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [indexPath row] % 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;  
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [listOfMovies release];
    [super dealloc];
}

@end

I have been trying (Without Success) to change the UITableView so the entries are left justified. I have read a lot of posts about UITableViews and I can only find settings for left justified when editing. How do I set it for just viewing and scrolling?

Thanks for the help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:49:22+00:00Added an answer on May 25, 2026 at 3:49 pm

    Remove this:

    - (NSInteger)tableView:(UITableView *)tableView 
    indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
        return [indexPath row] % 2;
    }
    

    This delegate method gets called for every row and the code here is returning a value of 1 every other row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand Ruby a bit better, I ran into this code surfing the
Trying to understand the math of this code snippet. A token is provided which
Trying to understand why this doesn't work. I keep getting the following errors: left
I was trying to understand the floating point representation in C using this code
I was trying to understand on how to detect the two peaks from the
I'm trying to understand the right way to return values in jquery from a
I am trying to understand the code for the mixins posted at this blog
I'm trying to understand what's really happening when I compile and execute C++ code,
I am trying to understand the difference between LEFT JOIN and LEFT JOIN FETCH
I'm still trying to understand this piece of code that I found in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.