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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:53:52+00:00 2026-06-09T14:53:52+00:00

I have designed a Table view , For Select Followers list to send message,

  • 0

I have designed a Table view , For Select Followers list to send message,
so there I can select some followers and then send them message on twitter.

I am using UITable View with UITableViewCellAccessoryCheckmark to make
this.

enter image description here

But when I scroll down table, the checked rows get unchecked every
time.

I have decleard table view and an array for selected followers in FollowersListView.h

@interface FollowersListView : UIViewController<UITableViewDelegate,UITableViewDataSource>{

IBOutlet UITableView *tableFollowers;

NSMutableArray *listFollowrsName;   
NSMutableArray *listSelectedFollowrsId;
}

@property(nonatomic,retain) NSMutableArray *listFollowrsName;    
@property(nonatomic,retain) NSMutableArray *listSelectedFollowrsId;

@end

and my tableview code is like this in FollowersListView.m file

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

    return [listFollowrsName count];
}



- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"CellWithSwitch"];
    //if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellWithSwitch"] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.font = [UIFont systemFontOfSize:14];

    //cell.accessoryType = UITableViewCellAccessoryCheckmark;
    cell.accessoryType = UITableViewCellStyleDefault;
    //}

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

    return cell;
}

//to select a row
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];


    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
        cell.accessoryType = UITableViewCellAccessoryNone;        
        NSLog(@"row is un-checked %@",[NSNumber numberWithInt:path.row]);
        [listSelectedFollowrsId removeObject:[NSNumber numberWithInt:path.row]];
        NSLog(@"Now selected person are%@",listSelectedFollowrsId);

    } else {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
        NSLog(@"row is checked %@",[NSNumber numberWithInt:path.row]);
        [listSelectedFollowrsId addObject:[NSNumber numberWithInt:path.row]];       
        NSLog(@"Now selected person are%@",listSelectedFollowrsId);
    }

}

I guess I need to load every cell as per the already stored selected list but not getting how to do.

Can anyone guide where I’m doing wrong,
Any help would be appreciated

Edit

@Novarg

I have declared “listSelectedFollowrsId” as a NSMutable Array in .h file and initialized in viewDidLoad method then adding/removing values in didSelectRowAtIndexPath method to manage selected rows.

  • 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-09T14:53:53+00:00Added an answer on June 9, 2026 at 2:53 pm

    The thing is that you create a new cell every time that you scroll. The if (cell == nil) condition must be there, otherwise you will just keep on re-writing the cell over and over again.

    Try the following:

    - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"CellWithSwitch"];
      if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellWithSwitch"] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.accessoryType = UITableViewCellStyleDefault;
      }
      NSString *cellValue = [listFollowrsName objectAtIndex:indexPath.row];
      cell.textLabel.text = cellValue;    
      return cell;
    }
    

    It might not work, I’m using a windows machine right now, so can’t compile the code and test it myself now.

    Hope it helps

    EDIT

    If it doesn’t solve the problem I’d also add a variable(probably an NSMutableDictionary) to keep a record of the names that have been “checked”. Using that you can add the following just before return cell; in cellForRowAtIndexPath: method:

    if ([[theDictionary objectForKey:/*your key here, can be anything*/]isEqualToString:/*string or whatever, just make sure that the checked ones are different from the unchecked ones*/])
      cell.accessoryType = UITableViewCellAccessoryCheckmark;
    else
      cell.accessoryType = UITableViewCellAccessoryNone;
    

    EDIT 2

    Here’s what you should add right before return cell;(didn’t see the listSelectedFollowrsId array before):

    cell.accessoryType = UITableViewCellAccessoryNone;
    for (int i = 0; i < [listSelectedFollowrsId count]; i++) {
      if ([[listSelectedFollowrsId objectAtIndex:i]intValue] == indexPath.row) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
      }
    }
    

    That will set the accessory to checkmark if the row has been previously tapped.

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

Sidebar

Related Questions

I am having 20 rows in a table view, and I have designed (or
I have a Table View Controller which I have designed using storyboards. This has
I have a table with 1million record and i designed 2queries. table index: id
I have SQL Server 2008 with a table called ProductCategories designed like this: Id
I have designed a page in Fireworks then imported it to Dreamweaver in CSS
I have a simple view function that's designed to allow the user to choose
I have a table called products in a MySQL database. products looks some what
I have created a grouped table view & I had a edit button in
I have UIView designed in IB, and UITableView on it. In view contoller's viewDidLoad
In my app I have a table view with 12 types of custom cells.

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.