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 7705311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:50:11+00:00 2026-05-31T23:50:11+00:00

So I’ve been given an assignment in my Mobile apps class: make a color

  • 0

So I’ve been given an assignment in my Mobile apps class: make a color game app for the iphone.(The description of how to game works is at the top of the pasted viewcontroller.h file below.)

I’m very new to Objective-C and cocoa, but have managed to troubleshoot and fix a lot of things in this app. The problem I have right now is that I don’t know how to properly initialize and send UITableViewCells to the view. I’m confused because all of the tutorials I’ve found online use datasource methods to change different attributes of the UITableView and the cells as well. I’m not sure how these methods will interact with the controls I’ve already placed. I’m confused because I added them by the storyboard file, not by defining tableview attributes with datasource code.

My immediate issue is that my program won’t display the proper text to the cells textlabel and detailtextlabel.

I’ve looked everywhere online for UITableView and UITableViewCell tutorials, but they are all from years ago and I’m not sure if the advent of the storyboard has changed the way I would treat these controls.

All of the code I’ve written is either in the viewcontroller.m or viewcontroller.h files.

The method within ViewController.m file, that should call the cell and display text and detail text:

-(IBAction)enterClicked
{
//On enter- send instance colors to the colorTable row[i], perform comparisons and append     the resulting symbols to the instanceResults String. Send instanceResults string to the resultTable     row[i]. When game counter reaches 6, gameOver. If on comparisons check, the instanceColors are     the same as the gameColors, then the player wins.

    [self checkForLoss];

    if(!self.gameOver)
    {
    resultOfGuess = [self comparePlayerInputToGameColors:guessColors];

    [listOfGuesses addObject:guessColors];
    [listOfOutcomes addObject:resultOfGuess];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_numberOfTurnsPlayed inSection:0];    

        UITableViewCell *thisCell = [[UITableViewCell alloc]      initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];

        thisCell.textLabel.text = [self.listOfGuesses lastObject];
        thisCell.detailTextLabel.text = [self.listOfOutcomes lastObject];

    [guessColors setString:@""];

    if([self checkForWin:resultOfGuess])
        [UpdateLabel setText:@"You have won!"];
    else
        [UpdateLabel setText:@""];

    self.colorCounter = 0;
    self.isStepOne = YES;
    _numberOfTurnsPlayed++;
    }

    else
    {
        if([self checkForLoss])
        [UpdateLabel setText:@"You have lost!"];
    }
}

The UITableView DataSource Methods I’ve called at the bottom of the viewcontroller.m file:

    #pragma mark - UITableViewDataSource protocol


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if(section == 0)
        return @"Guesses:  Results:";
    return 0;
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1     reuseIdentifier:CellIdentifier];
    }
    return cell;
}  

So my questions are: Can I change a control’s properties with datasource methods, if I created the controls through the storyboard? How do I properly display the text in a uitableview’s cells?

Edit/update: Thank you, I’ve used your advice jrturton, but now I’ve found something peculiar that may be the source of my problems. in my viewController.h file I’ve changed my header from

ViewController: UIViewController to ViewController: UITableViewController

Thinking that the datasource methods I call within the viewcontroller files have to be able to call the same methods and properties of the class that I call in the header– Also, I see this done in other UITableView tutorial files.

The problem is that when I change the header to read– ViewController: UITableViewController — and I try to compile, I get this error:

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘-[UITableViewController loadView] loaded the “2-view-3” nib but didn’t get a UITableView.’
It compiles fine if I use just :UIViewController in the header file though.

Any ideas?

Further update: I”ve noticed within my storyboard that the only available ViewController object is a UIViewController object, while in the other tutorial files I’ve seen, this ViewController object is a UITableViewController object. I imagine this is my problem, but I can’t seem to switch my UIViewController object to a UITableViewController. All I can do is create a new one, which isn’t what I want, I imagine.

  • 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-31T23:50:13+00:00Added an answer on May 31, 2026 at 11:50 pm

    Your action method should update the data model (which I think it does, since it changes your listOfGuesses array). You then need to let your table view know that you have added or updated rows so that it can re-load them for you – check the UITableView documentation for reloading data or specific rows.

    Creating a cell outside of the datasource methods isn’t going to let that cell appear in your table.

    At the moment I’m guessing you have 6 empty cells in your table view? You need to populate the text and detail labels in your cellForRowAtIndexPath method. The difference now there are storyboards is that you don’t need to do the if (cell == nil) bit, as long as you have set the re-use identifier in your storyboard prototype cell then it will do all that for you. So your cellForRowAtIndexPath method can be reduced to:

    -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
    {     
        // This will dequeue or create a new cell based on the prototype in your storyboard    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    
        // Put your actual configuration here based on your model array
        cell.textLabel.text = @"Hello";     
    
        return cell; 
    } 
    

    Further hints (this is homework so I’m not giving full samples)

    • ‘indexPath.row` in the above method will give you the index from your model array that the cell refers to
    • You have defined the table as having 6 rows, but you are adding items to your model arrays as you go – so when the table asks for row 5, and your model only has 3 entries, you need to deal with this. Consider changing the number of rows in the table dynamically and using table view methods to indicate that new rows have been added. Again, see the UITableView documentation for this.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.