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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:21:46+00:00 2026-05-13T22:21:46+00:00

I have a tableView:didSelectRowAtIndexPath: where I create a ViewController-Instance each time an item is

  • 0

I have a tableView:didSelectRowAtIndexPath: where I create a ViewController-Instance each time an item is selected. Sometimes it works fine for a long time, sometimes it crashes with a EXC_BAD_ACCESS very quickly. The debugger blames the line [super dealloc]; in the QuestionDetailViewController.

Why? I log the QuestionDetailViewController retainCount. That looks fine.

QuestionDetailViewController

#import <UIKit/UIKit.h>
#import "Question.h"
#import "Answer.h"
@interface QuestionDetailViewController : UIViewController < UIScrollViewDelegate , QuestionDetailViewProtocol> {
    Question *question;
    UILabel *answerText;
    UILabel *titleLabel;
}

@property(nonatomic,retain) Question *question;
@property(nonatomic,retain) UILabel *answerText;
@property(nonatomic,retain) UILabel *titleLabel;

@end


#import "QuestionDetailViewController.h"
@implementation QuestionDetailViewController
@synthesize question;
@synthesize answerText;
@synthesize titleLabel; 


- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated {
    UIColor *bgColor = [UIColor colorWithRed:199.0/255 green:234.0/255 blue:251.0/255 alpha:1];
    self.answerText = (UILabel *)[self.view viewWithTag:2]; 
    self.answerText.backgroundColor = bgColor;
    self.answerText.text = self.question.answer.text;
    self.titleLabel = (UILabel*)[self.view viewWithTag:1]; 
    CGSize sizeTitle = [self.question.title sizeWithFont:[titleLabel font]
                                       constrainedToSize:CGSizeMake(280.0, INFINITY) 
                                           lineBreakMode:UILineBreakModeWordWrap];
    self.titleLabel.text = self.question.title;
    self.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
    self.titleLabel.frame = CGRectMake(10,10, 260, sizeTitle.height);

    CGSize sizeText = [self.question.answer.text sizeWithFont:[self.answerText font]
                                            constrainedToSize:CGSizeMake(280.0, INFINITY) 
                                                lineBreakMode:UILineBreakModeWordWrap];
    self.answerText.frame = CGRectMake(0,20+sizeTitle.height, 310, sizeText.height+sizeTitle.height);
    [(UIScrollView *)self.view setContentSize:CGSizeMake(280, answerText.frame.size.height +sizeTitle.height)];
    self.view.backgroundColor = bgColor;
    [super viewWillAppear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    NSLog(@"%d", [self retainCount]);
    [super viewDidDisappear:animated];
    [self release];
}

-(IBAction)goBack:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)dealloc {
    NSLog(@"QDC dealoc");
    [self.answerText release];
    [self.titleLabel release];
    [self.question release];
    [super dealloc];
}

@end

tableView:didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {   
    QuestionDetailViewController *qdc = [[QuestionDetailViewController alloc] initWithNibName:@"QuestionDetailViewController" bundle:nil];
    Question* question;
    if ([filteredQuestions count]>0) {
        question = [self.filteredQuestions objectAtIndex:indexPath.row];
    } else {
        question = [self.questions objectAtIndex:indexPath.row];
    }
    [qdc setQuestion:question];
    [question release];
    NSLog(@"%d", [qdc retainCount]);
    [self.navigationController pushViewController:qdc animated:YES];
    [qdc release];
}
  • 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-13T22:21:47+00:00Added an answer on May 13, 2026 at 10:21 pm

    This:

    - (void)viewDidDisappear:(BOOL)animated {
        NSLog(@"%d", [self retainCount]);
        [super viewDidDisappear:animated];
        [self release];
    }
    

    looks incredibly suspicious. Did you do [self retain]? If not, then why are you releasing? If you are, you’re probably doing something wrong, because [self retain] is an incredibly rare thing to need to do.

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

Sidebar

Related Questions

I have a TableView associated to a TreeView. Each time a node in the
I have a Tableview on AppDelegate That calls a SecondView (dvController) when DidSelectRowAtIndexPath using:
I have tableview, where create new rows and set them layout manually. In every
I have a tableView that present a list of Books, each of the table
I create UITableView and I have 3 cells , so each cell should push
I have the following code : - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UIWebView *aWebView;
I have a custom view controller showing the details of the selected item in
I have the following code in my didSelectRowAtIndexPath delegate method: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
I have TableView. My datasource is SQLite database. I'm trying to count a number
I have a tableView with a few sections and I have it set for

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.