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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:12:46+00:00 2026-06-12T08:12:46+00:00

I’m having an issue iterating over an NSMutableArray of custom objects. Whenever I run

  • 0

I’m having an issue iterating over an NSMutableArray of custom objects. Whenever I run the following code, it will iterate over the array 6 times, despite there only being 2 objects in the NSMutableArray object.

//Configure the Settings Screen
[self addSection:^(JMStaticContentTableViewSection *section, NSUInteger sectionIndex) {

    section.title = @"Twitter Accounts";

    //alloc and init the twitterSwitchesArray to store the switches used in the view
    self.twitterSwitchesArray = [[NSMutableArray alloc] initWithCapacity:[self.twitterAccounts count]];

    NSLog(@"LOADING: twitterAccounts Array count: %i", [self.twitterAccounts count]);

    for(MessageBlastSavedTwitterAccount *twitterAccount in _twitterAccounts)
    {
        NSLog(@"Configuring: %@", twitterAccount.twitterAccountDescription);

        //Configure the Twitter Setting Switch
        [section addCell:^(JMStaticContentTableViewCell *staticContentCell, UITableViewCell *cell, NSIndexPath *indexPath) {

            UISwitch *twitterSwitch = [[UISwitch alloc] init];
            twitterSwitch.accessibilityLabel = twitterAccount.twitterAccountDescription;
            twitterSwitch.on = [self switchShouldBeFlippedForTwitterAccount:twitterAccount.twitterAccountDescription];

            NSLog(@"LOADING: Twitter account %@, should be enabled: %i", twitterAccount.userEnteredDescription, [self switchShouldBeFlippedForTwitterAccount:twitterAccount.twitterAccountDescription]);

            [self.twitterSwitchesArray addObject:twitterSwitch];

            [twitterSwitch addTarget:self action:@selector(flippedTwitterSwitch:) forControlEvents:UIControlEventValueChanged];

            staticContentCell.reuseIdentifier = @"UIControlCell";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.textLabel.text = [twitterAccount userEnteredDescription];
            cell.imageView.image = [UIImage imageNamed:@"210-twitterbird.png"];
            cell.accessoryView = twitterSwitch;
        }];
    }
}];

I get the following output:

2012-10-04 20:47:27.703 MessageDraft[1206:c07] LOADING: twitterAccounts Array count: 2
2012-10-04 20:47:27.703 MessageDraft[1206:c07] Configuring: coryb
2012-10-04 20:47:27.704 MessageDraft[1206:c07] LOADING: Twitter account @coryb, should be enabled: 1
2012-10-04 20:47:27.705 MessageDraft[1206:c07] Configuring: cocoaapp
2012-10-04 20:47:27.706 MessageDraft[1206:c07] LOADING: Twitter account @cocoaapp, should be enabled: 1
2012-10-04 20:47:27.708 MessageDraft[1206:c07] LOADING: Twitter account @coryb, should be enabled: 1
2012-10-04 20:47:27.709 MessageDraft[1206:c07] LOADING: Twitter account @cocoaapp, should be enabled: 1
2012-10-04 20:47:27.713 MessageDraft[1206:c07] LOADING: Twitter account @coryb, should be enabled: 1
2012-10-04 20:47:27.714 MessageDraft[1206:c07] LOADING: Twitter account @cocoaapp, should be enabled: 1

I have even tried a manual way (below) to iterate over the array, and I still have the exact same issue:

// The self.twitterAccounts count returns a 2, so this should only repeat twice.
    for(int i = 0; i < [self.twitterAccounts count]; i++)
    {
        NSLog(@"%i", i);

        //Configure the Twitter Setting Switch
        [section addCell:^(JMStaticContentTableViewCell *staticContentCell, UITableViewCell *cell, NSIndexPath *indexPath) {

            UISwitch *twitterSwitch = [[UISwitch alloc] init];
            twitterSwitch.tag = i;
            twitterSwitch.on = [self switchShouldBeFlippedForTwitterAccount:_twitterAccount.description];

            self.twitterAccount = [_twitterAccounts objectAtIndex:i];

            NSLog(@"LOADING: Twitter account %@, should be enabled: %i", _twitterAccount.userEnteredDescription, [self switchShouldBeFlippedForTwitterAccount:_twitterAccount.description]);

            [self.twitterSwitchesArray addObject:twitterSwitch];

            [twitterSwitch addTarget:self action:@selector(flippedTwitterSwitch:) forControlEvents:UIControlEventValueChanged];

            staticContentCell.reuseIdentifier = @"UIControlCell";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.tag = i;
            cell.textLabel.text = [_twitterAccount userEnteredDescription];
            cell.imageView.image = [UIImage imageNamed:@"210-twitterbird.png"];
            cell.accessoryView = twitterSwitch;
        }];
    }
}];

Any help with this issue would be greatly appreciated!

  • 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-12T08:12:47+00:00Added an answer on June 12, 2026 at 8:12 am

    I’m the creator of JMStaticContentTableViewController.

    The addCell: method is not getting called multiple times. The JMStaticContentTableViewCellBlock block you pass into the addCell: method gets called as part of the tableView:cellForRowAtIndexPath: method of the controller.

    It does this so that you can properly configure UITableViewCells and they get reused efficiently.

    After reviewing your code above, I’d suggest that you iterate through twice, once to configure your twitterSwitchesArray properly, and another with the code you’d like called in the tableView:cellForRowAtIndexPath: method.

    You can look at an example of doing a for loop, and running loop-safe code inside of the JMStaticContentTableViewCellBlock right here.

    JMStaticContentTableViewController is designed so that you can still “think” of it in the same way as the traditional delegate-based UITableViewController model, but using blocks instead.

    That’s why JMStaticContentTableViewCellBlock passes in a UITableViewCell instance, this is so you can treat it like what you would be handed from the dequeueReusableCellWithIdentifier: method of UITableView. It also passes in JMStaticContentTableViewCell model object instance so that you can configure a few things that wouldn’t make sense or wouldn’t be possible on the standard UITableViewCell object, like tableViewCellSubclass or cellHeight.

    Hope this helps!

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an array which has BIG numbers and small numbers in it. I

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.