Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason you're crashing is that you're assigning a value to a global variable (<code>selectedindex</code>), but you're never taking ownership of it by calling <code>-retain</code>. 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.</p> <p>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:</p> <pre><code>[selectedindex release]; selectedindex = [[NSString stringWithFormat:@"%d", indexPath.row] retain]; </code></pre> <p>That will fix your crash.</p> <p>Now that your crash is fixed, though, you should really rethink your design. There's no reason for <code>selectedindex</code> to be a global variable; since the selected index is very likely specific to that instance of your <code>ContactsController</code>, 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 <code>selectedIndex</code> shared between ALL instances of <code>ContactsController</code>. Then, in turn, your <code>+returnselectedindex</code> 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.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload