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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:27:51+00:00 2026-05-17T18:27:51+00:00

I am doing this with UISwitchs and UITextFields… I have declared the UISwitch as

  • 0

I am doing this with UISwitchs and UITextFields…

I have declared the UISwitch as Property in the header file, because I want to access its value in several different methods within my class.

I am adding the UISwitch to one of my TableViewCells, using the following code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
cell.accessoryView = mySwitch;
mySwitch.on = YES;

return cell;

} 

As it is, the retainCounts are all over the place. The mySwitch Retain is 2 by the time the cell has been put on the screen, and every time I tap the switch, the retain count goes up, until it gets to 4, then it seems to stay there.

Obviously I am missing something. If someone can point me in the right direction, it 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-05-17T18:27:51+00:00Added an answer on May 17, 2026 at 6:27 pm

    Chasing the retainCount of an object is not something that you want to do whenever private api’s are interacting with it. All that you want to do is to track your own retain counts and then make sure you are incrementing it and decrementing it as necessary. Assuming you have something like the following:

    @property (nonatomic, retain) UISwitch *mySwitch;
    
    @synthesize mySwitch;
    

    You should change your code that you have above to be this:

    self.mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
    cell.accessoryView = mySwitch;
    mySwitch.on = YES;
    

    In the code you have above, you do not own mySwitch anymore as you told it to autorelease. However, by using self.mySwitch you will be retaining the property when you create it there. Then you can use it as you wish throughout the rest of the program. Just make sure to release it safely in dealloc.

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

Sidebar

Related Questions

I'm probably doing this all wrong. I have a text file full of data
I have some code doing this : var changes = document.getElementsByName(from); for (var c=0;
any problems with doing this? int i = new StreamReader(file.txt).ReadToEnd().Split(new char[] {'\n'}).Length
Does anyone have any experience with doing this? I'm working on a Java decompiler
im doing this query on mysql, but its giving me duplicate results sets: this
Would doing this be consider good practice... I have class A with the following
Is doing this less efficient than setting up a background worker thread? Because it
Im doing something like this to get a list of all users that have
I'm doing this problem: http://www.codechef.com/problems/FCTRL I have the solution, but, the memory usage is
I'm doing this: urlparse.urljoin('http://example.com/mypage', '?name=joe') And I get this: 'http://example.com/?name=joe' While I want to

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.