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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:15:25+00:00 2026-06-12T17:15:25+00:00

I am currently creating a portion of my iPhone app to basically have a

  • 0

I am currently creating a portion of my iPhone app to basically have a list of cells (in a tableview) That act like the existing apple notepad.

I am trying to make it so the names of the cells have the names of strings in an array. This is what I am currently doing.

@interface ViewController ()
{
NSMutableArray *cameraArray;
NSMutableArray *notesArray;
NSMutableArray *voiceArray;
}
@end

@implementation ViewController
//@synthesize myTableView;
- (void)viewDidLoad
{
[super viewDidLoad];

NSUserDefaults *ud=[NSUserDefaults standardUserDefaults];
//[ud setObject:@"Archer" forKey:@"char1class"];
[ud synchronize];
NSString *key1;//[ud stringForKey:@"Key1"];
NSString *key2; //[ud stringForKey:@"Key1"];
NSString *key3; //[ud stringForKey:@"Key1"];

if([ud stringForKey:@"Key1"] == nil){
    key1 = @"Open Camera Slot";
}else{
    key1 = [ud stringForKey:@"key1"];
}

if([ud stringForKey:@"Key2"] == nil){
    key2 = @"Open Camera Slot";
}else{
    key2 = [ud stringForKey:@"key2"];
}

if([ud stringForKey:@"Key3"] == nil){
    key3 = @"Open Camera Slot";
}else{
    key3 = [ud stringForKey:@"key3"];
}

cameraArray = [[NSMutableArray alloc]initWithObjects:key1, key2, key3, nil];


}

//tableview datasource delegate methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return cameraArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath{


CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];


if(cell == nil){
    cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:@"Cell"];
}

NSEnumerator *enumerator = [cameraArray objectEnumerator];
id anObject;
NSString *cellName = nil;
while (anObject = [enumerator nextObject]) {
   cellName = anObject;
}
//static NSString *cellName = [cameraArray.objectAtIndex];
cell.textLabel.text = [NSString stringWithFormat:cellName];
return cell;

}

So I am basically creating the strings in cameraArray from keys in the NSUserDefaults (im just doing this for testing purposes, the strings will be user entered later on)

What I’m stuck on is the enumerator goes through the array just fine, but only uses the last value (the third one) on all of the cells in the tableView.

So if there were three strings, “first” “second” and “third” All three of the cells say “third”

How do I fix this?

  • 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-12T17:15:26+00:00Added an answer on June 12, 2026 at 5:15 pm

    There are several things wrong with this code. ‘rdelmar’ posted the basic answer in his comment. I thought I’d walk a few things as a learning exercise.

    You are using an enumerator here to walk through the values of an array. There is a much simpler way. Note that this isn’t needed for your code. I am pointing this out for future reference.

    Replace the enumerator, anObject, cellName, and the while-loop with this:

    for (NSString *cellName in cameraArray) {
        // Do something with cellName
    }
    

    This is a much easier way to walk through all the values of an array of NSString objects. If the array contains objects of a different type then replace NSString with the appropriate type.

    Next is your use of creating a new string combined with using stringWithFormat:. Neither is needed in such a case. In the code you posted, cellName is already an NSString reference. Just assign it directly such as:

    cell.textLabel.text = cellName;
    

    No need to create a new NSString object. And you should only use string formats when you actually have a string format.

    Hope that helps.

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

Sidebar

Related Questions

I'm currently creating an iPhone app (Xcode 4.3.1, IOS 5) that could use Bluetooth
im currently creating a graph for an app, using coreplot and have a problem
I am currently creating an app and would like to create a demo version
I have a portion of a website I am creating that is as follows:
I'm currently creating a iOS 5 iPad app where there will be heavy network
I'm currently creating both the client and server app using ActiveResource for web servicing.
I'm currently creating a stock management system that uses multiple warehouses (with sub locations)
I have used Android phonegap application for creating dynamic list with label and corresponding
I'm currently creating a small C# program that inserts data from files into a
We are currently facing the following problem: We have an application that needs to

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.