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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:26:16+00:00 2026-05-20T01:26:16+00:00

i have a tableview controller like so, NSString *selectedindex; @interface ContactsController : UITableViewController<ABPeoplePickerNavigationControllerDelegate> {

  • 0

i have a tableview controller like so,

NSString *selectedindex;
@interface ContactsController : UITableViewController<ABPeoplePickerNavigationControllerDelegate> {
    NSMutableArray *names;
    NSMutableArray *phonenumbers;
    NSMutableArray *contacts;
    DatabaseCRUD *sampledatabase;   
}

+(NSString *) returnselectedindex;
@end

in the implementation file i have

+(NSString *) returnselectedindex
{
    return selectedindex;
}

when a row is selected in the tableview i put have the following code.

selectedindex = [NSString stringWithFormat:@"%d", indexPath.row];
NSLog(@"selected row is %@",selectedindex);

in a different class i am trying to access the selectedindex. like so

selected = [ContactsController returnselectedindex];
NSLog(@"selected is %@",selected);

it gives me a warning: 'ContactsController' may not respond to '+returnselectedindex'

and crashes. i am not sure why. i have used class methods previously lot of times , and never had a problem. any help please. Thank You.

  • 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-20T01:26:17+00:00Added an answer on May 20, 2026 at 1:26 am

    The reason you’re crashing is that you’re assigning a value to a global variable (selectedindex), but you’re never taking ownership of it by calling -retain. As a result, the string doesn’t know you need it to stay around, so the system deallocates it. Later, when you try to access it, it’s already deallocated.

    In order to avoid the crash, you need to add a retain call when you assign the value. Of course, since a selected index is something that’s likely to be changing often, you’d want to release the previous value before overwriting it and retaining the new one. Thus, you should have this code:

    [selectedindex release];
    selectedindex = [[NSString stringWithFormat:@"%d", indexPath.row] retain];
    

    That will fix your crash.

    Now that your crash is fixed, though, you should really rethink your design. There’s no reason for selectedindex to be a global variable; since the selected index is very likely specific to that instance of your ContactsController, it should be an instance variable of that class. Instead, you’ve declared it as a global variable, which means that there is only one selectedIndex shared between ALL instances of ContactsController. Then, in turn, your +returnselectedindex method should be an instance method, not a class method. (It should also be renamed in order to follow Cocoa naming conventions, but that’s well off topic.)

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

Sidebar

Related Questions

I have this code in my table view controller (and delegate): - (void)tableView:(UITableView *)tableView
I have a tableview inside a viewcontroller I would like to edit/delete rows. It
I have a view controller which has a tableview subview. I have made the
I have a grouped table view with textfields in the tableview. For the keyboard
Here's my case: I have a table view showing contacts. Add button in the
I have a tableView that needs to be updated after information has been inserted
i have this MainViewController, which is a controller for my table view. Whenever I
I have a snippet to create a 'Like' button for our news site: <iframe
I have a navigation controller based app. My views consist of two tableviews laid
So I have a view controller with a single UITableView that shows a string

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.