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

  • SEARCH
  • Home
  • 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 8145155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:34:40+00:00 2026-06-06T13:34:40+00:00

I’m pretty new to objective-C (and C in general) and iPhone development and am

  • 0

I’m pretty new to objective-C (and C in general) and iPhone development and am coming from the java island, so there are some fundamentals that are quite tough to learn for me.

I’m diving right into iOS5 and want to use storyboards.

For now I am trying to setup a list in a UITableViewController that will be filled with values returned by a web service in the future. For now, I just want to generate some mock objects and show their names in the list to be able to proceed.

Coming from java, my first approach would be to create a new Class that provides a global accessible method to generate some objects for my list:

#import <Foundation/Foundation.h>

@interface MockObjectGenerator : NSObject

+(NSMutableArray *) createAndGetMockProjects;

@end

Implementation is…

#import "MockObjectGenerator.h"

// Custom object with some fields    
#import "Project.h"

@implementation MockObjectGenerator

+ (NSMutableArray *) createAndGetMockObjects {

    NSMutableArray *mockProjects = [NSMutableArray alloc];

    Project *project1 = [Project alloc];
    Project *project2 = [Project alloc];
    Project *project3 = [Project alloc];

    project1.name = @"Project 1";
    project2.name = @"Project 2";
    project3.name = @"Project 3";

    [mockProjects addObject:project1];
    [mockProjects addObject:project2];
    [mockProjects addObject:project3];

    // missed to copy this line on initial question commit
    return mockObjects;

}

And here is my ProjectTable.h that is supposed to control my ListView

#import <UIKit/UIKit.h>

@interface ProjectsTable : UITableViewController

@property (strong, nonatomic) NSMutableArray *projectsList;

@end

And finally ProjectTable.m

#import "ProjectsTable.h"
#import "Project.h"
#import "MockObjectGenerator.h"

@interface ProjectsTable {

@synthesize projectsList = _projectsList;

-(id)initWithStyle:(UITableViewStyle:style {

    self = [super initWithStyle:style];

    if (self) {

        _projectsList = [[MockObjectGenerator createAndGetMockObjects] copy];

    }

    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // only one section for all
    return 1;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    NSLog(@"%d entries in list", _projectsList.count);
    return _projectsList.count;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // the identifier of the lists prototype cell is set to this string value
    static NSString *CellIdentifier = @"projectCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Project *project = [_projectsList objectAtIndex:indexPath.row];

    cell.textLabel.text = project.name

    return cell;
}

So while I think everything is correctly set, I expect the tableView to show my three mock objects in its rows. But it stays empty and the NSLog method prints “0 entries in list” into the console. So what am I doing wrong?

Any help is appreciated.

Best regards
Felix

Update 1: missed to copy the two return statements into this box (“return mockObjects” and “return cell”) which were already in my code, now inserted.

  • 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-06-06T13:34:42+00:00Added an answer on June 6, 2026 at 1:34 pm

    You have at least two problems in your code:

    In

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    

    You are supposed to return a valid UITableViewCell (just return cell;)

    You should also init the objects you allocate:

    NSMutableArray *mockProjects = [NSMutableArray alloc];
    
    Project *project1 = [Project alloc];
    Project *project2 = [Project alloc];
    Project *project3 = [Project alloc];
    

    To do so write mockProjects = [[NSMutableArray alloc]init]; and same for the Project objects.

    In the method you also need to return the object you create: return mockProjects;

    I would strongly recommend that you check up on the Automatic reference Counting system, or try to learn the good ol’ fashioned memory management model of iOS. It is very different from the Java way of doing things.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.