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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:29:12+00:00 2026-05-24T06:29:12+00:00

i have a very simple table with only one row that has a uiswitch

  • 0

i have a very simple table with only one row that has a uiswitch on it. basically, once the user turns the switch on, i’d like to add another row below the first row. nothing seems to be working properly even after going through many threads here. in the best case, i can add another row but in a new section, which is not what i want.

here is some of my code:

LoadDidView:

  listOfItems = [[NSMutableArray alloc] init];
  listOfItems = [NSMutableArray arrayWithObjects:@"LINE 1" ,nil];    



- (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]; //try here diff styles
}

NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;


switch1 = [[UISwitch alloc] initWithFrame:CGRectZero];
[switch1 addTarget:self action:@selector(toggleEnabledTextForSwitch1onSomeLabel:) forControlEvents:UIControlEventValueChanged];

[cell addSubview:switch1];
cell.accessoryView = switch1;



return cell;

}

And the action associated with my switch:

- (IBAction) toggleEnabledTextForSwitch1onSomeLabel: (id) sender {  
if (switch1.on) {

  [listOfItems insertObject:@"LINE 2" atIndex:0];
   [tblSimpleTable reloadData];

    }

 }

I read somewhere that I need to use insertRowsAtIndexPaths: but i have no idea if i really need it in my case since I am not doing any editing to my cells – just adding one cell to the same section.

Is this the right way to do that? what am i doing wrong here?

Thanks!

EDIT:

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

    int count = [listOfItems count];
    if(self.editing) {
    count++;

}
    return count;
}
  • 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-24T06:29:13+00:00Added an answer on May 24, 2026 at 6:29 am

    Did you change the value that numberOfRowsInSection returns, and then reloadData?

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

Sidebar

Related Questions

I have a submission table that is very simple: userId, submissionGuid I want to
I have a very simple table and I can happily query it using LINQ
I have very simple select like this: SELECT * FROM table WHERE column1 IN
i have very simple problem. I need to create model, that represent element of
I have a very simple bit of script that changes the status of an
I have a very simple Java RMI Server that looks like the following: import
I have a very simple ASP.Net page that acts as a front end for
I have a script that appends some rows to a table. One of the
I have very simple script for submitting the form. This is html template: <table>
So I have this simple PHP loop that is generating html table data with

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.