UITextView setEditing:YES makes the control of the TextView scroll? - iphone

I have a UITableViewCell that has an integrated UITextView. The goal is to make a cell that auto-expands while editing. The issue right now is that when the UITableViewController sends setEditing:YES, the UITextView scrolls and clips some of the text at the top.
I'm sure there is a better way to do this but I just don't know how...
#import "PLTextViewCell.h"
#implementation PLTextViewCell
#synthesize delegate=_delegate;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
_textView = [[UITextView alloc] initWithFrame:CGRectMake(90, 0, 200, 80)];
[_textView setEditable:NO];
[_textView setFont:[UIFont systemFontOfSize:15.0]];
[_textView setDelegate:self];
[_textView setScrollEnabled:NO];
[[self contentView] addSubview:_textView];
}
return self;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[_textView setEditable:editing];
[_textView scrollRangeToVisible:NSMakeRange(0, 1)];
[self textViewDidChange:_textView];
}
- (void)dealloc {
[_textView dealloc];
[super dealloc];
}
- (void)setTextValue:(NSString *)value {
[_textView setText:value];
[self textViewDidChange:_textView];
}
- (NSString *)textValue {
return [_textView text];
}
- (CGFloat)cellHeight {
CGSize mySize = [_textView contentSize];
NSLog(#"cell height: %f", mySize.height);
return mySize.height;
}
#pragma mark -
#pragma mark Text view delegate
- (void)textViewDidChange:(UITextView *)textView {
CGSize mySize = [_textView contentSize];
if (mySize.height > self.bounds.size.height) {
[textView scrollRectToVisible:CGRectMake(0,textView.contentSize.height-1,1,1) animated:NO];
if ([self delegate] != nil) {
[[self delegate] tableViewCellDidChangeHeight:self];
}
[textView setFrame:CGRectMake(90, 0, mySize.width, mySize.height)];
[self setNeedsLayout];
}
}
#end
Then the Table view implements a delegation method:
- (void)tableViewCellDidChangeHeight:(PLTextViewCell *)cell {
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
Any ideas? Am I doing this all wrong?

Turns out that it was the UIEdgeInset combined with my textview not being tall enough. My mistake!

Related

cannot remove UISearchBar

I create SearchBarView, a subclass of UIView, and added UISearchBar as a subview to it. After calling removeFromSuperview on SearchBarView (from searchBarSearchButtonClicked) the UISearchBar does not disappear. I tried to call removeFromSuperview on SearchBarView from where I created SearchBarView but it did not help. Any ideas why?
#import <UIKit/UIKit.h>
#interface SearchBarView : UIView <UISearchBarDelegate> {
UISearchBar *querySearchBar;
}
#end
#import "SearchBarView.h"
#implementation SearchBarView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
querySearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,frame.size.width,44)];
querySearchBar.delegate = self;
[self addSubview:querySearchBar];
}
return self;
}
#pragma mark -
#pragma mark UISearchBarDelegate methods
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[self removeFromSuperview];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
searchBar.text = #"";
[searchBar resignFirstResponder];
[searchBar setShowsCancelButton:NO animated:YES];
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:NO animated:YES];
return YES;
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:YES animated:YES];
return YES;
}
#end
SearchBarView is created as follows:
SearchBarView *searchBarView = [[SearchBarView alloc] initWithFrame:CGRectMake(0, 0, 480, 300)];
UIView *rootView = [[[[UIApplication sharedApplication] delegate] window] rootViewController].view;
[rootView addSubview:searchBarView];
Your problem is
[self addSubview:querySearchBar];
If you add searchcontroller to subview, then when you do these it does not work.
[searchController.searchBar removeFromSuperview()]
self.definesPresentationContext = true
searchController.active = false
I suggest your to do
presentViewController(searchController, animated: true, completion: nil)
And try to dismiss searchController
[searchController.searchBar removeFromSuperview()]
try
[searchbar removefromsuperview];

Can not get UITableView to Display NSArray

Sounds like a question that has been answered... maybe but i have checked all of the possible solutions i believe and nothing will work for me.
My .h file looks like this
#import <UIKit/UIKit.h>
#interface epsMenuPage : UIViewController<UITableViewDelegate,UITableViewDataSource>{
NSArray *listData;
...
UITableView *menuList;
...
}
#property (nonatomic,retain) NSArray *listData;
...
#property (nonatomic, retain) IBOutlet UITableView *menuList;
...
#end
My .m file looks like this
#implementation epsMenuPage
#synthesize listData;
...
#synthesize menuList;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
//Arrays credit,debit and both
creditListData = [[NSArray alloc]initWithObjects:#"Return",#"Force Sale",#"Authorize Only",#"Total Sales",#"Items Sold",#"Reciept's", nil];
debitListData = [[NSArray alloc]initWithObjects:#"Return",#"Force Sale",#"Authorize Only",#"Total Sales",#"Items Sold",#"Reciept's", nil];
bothListData = [[NSArray alloc]initWithObjects:#"Batch History",#"Settle Batch", nil];
self.listData = creditListData;
[menuList reloadData];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.view.backgroundColor =[UIColor colorWithRed:255/255.0 green:95/255.0 blue:95/255.0 alpha:1.0];
[colorChange setBackgroundColor:[UIColor colorWithRed:255/255.0 green:95/255.0 blue:95/255.0 alpha:1.0]];
[self.view addSubview:creditTabButton];
[self.view addSubview:debitTabButton];
[self.view addSubview:bothTabButton];
[self.view addSubview:creditButtonText];
[self.view addSubview:debitButtonText];
[self.view addSubview:bothBottonText];
[self.view addSubview:colorChange];
}
- (void)viewDidUnload
{
[self setTitleBAckButton:nil];
[self setTitleSettingsButton:nil];
[self setCreditTabButton:nil];
[self setDebitTabButton:nil];
[self setBothTabButton:nil];
[self setMenuList:nil];
[self setColorChange:nil];
[self setCreditButtonText:nil];
[self setDebitButtonText:nil];
[self setBothBottonText:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = #"tableID";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [self.listData objectAtIndex:row];
return cell;
}
- (void)dealloc {
[titleBAckButton release];
[titleSettingsButton release];
[creditTabButton release];
[debitTabButton release];
[bothTabButton release];
[menuList release];
[colorChange release];
[creditButtonText release];
[debitButtonText release];
[bothBottonText release];
[listData release];
[super dealloc];
}
- (IBAction)titleBackClick:(id)sender {
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
- (IBAction)titleSettingsClick:(id)sender {
}
- (IBAction)creditTabClick:(id)sender {
self.listData = creditListData;
[menuList reloadData];
[colorChange setBackgroundColor:[UIColor colorWithRed:255/255.0 green:95/255.0 blue:95/255.0 alpha:1.0]];
[self.view addSubview:creditTabButton];
[self.view addSubview:creditButtonText];
[self.view addSubview:colorChange];
self.view.backgroundColor = [UIColor colorWithRed:255/255.0 green:95/255.0 blue:95/255.0 alpha:1.0];
}
- (IBAction)debitTabClick:(id)sender {
self.listData = debitListData;
[menuList reloadData];
[colorChange setBackgroundColor:[UIColor colorWithRed:244/255.0 green:133/255.0 blue:33/255.0 alpha:1.0]];
[self.view addSubview:debitTabButton];
[self.view addSubview:debitButtonText];
[self.view addSubview:colorChange];
self.view.backgroundColor = [UIColor colorWithRed:244/255.0 green:133/255.0 blue:33/255.0 alpha:1.0];
}
- (IBAction)bothTabClick:(id)sender {
self.listData = bothListData;
[menuList reloadData];
[colorChange setBackgroundColor:[UIColor colorWithRed:72/255.0 green:72/255.0 blue:255/255.0 alpha:1.0]];
[self.view addSubview:bothTabButton];
[self.view addSubview:bothBottonText];
[self.view addSubview:colorChange];
self.view.backgroundColor = [UIColor colorWithRed:72/255.0 green:72/255.0 blue:255/255.0 alpha:1.0];
}
#end
I really for the life of me can not figure out why it wont display to my TableView, i have tried so many different tutorials.
any help is greatly appreciated.
You're never adding the menuList table view to your view. Add it and see if that does the trick:
// In -viewDidLoad
[self.view addSubview:menuList];
EDIT 1: Did you declare properties in your .h? These aren't visible, so it appears as if you're not creating or adding your table view to the view controller's view. However, if you are using IBOutlets, then this probably isn't the issue.
EDIT 2: From the comments below, your dataSource is nil, which is exactly why nothing is being displayed. Make sure your table view in Interface Builder has its dataSource outlet pointing to your view controller. To be double sure, delete the table view from Interface Builder and add it back again. Make sure your connections are exactly right. Also try cleaning the project and rebuilding, as well as restarting Xcode.
It looks like you are missing the required datasource method:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; {
return 1;
}
Also, it looks like you are not actually initializing your UIButton's, or anything you are adding as a subview. Are you using a nib?

UITableView scrolls too far when editing embedded UITextView

I've successfully embedded a UITextView inside a UITableViewCell, and most of the table is working fine. However, when I enable editing on the UITextView and start editing, the table shifts up too far, obscuring the cursor. Is there a way to control how far the tableview scrolls? Manually scrolling the view to the cell works, but the view still scrolls up before scrolling back down and into view.
Here is an example of what I mean:
editing a UITextField - the field is neatly placed directly above the keyboard.
http://imageshack.us/photo/my-images/13/textfield.png/
editing a UITextView - the field is placed significantly above the keyboard removing the toolbar from the keyboard doesn't affect anything)
http://imageshack.us/photo/my-images/809/textview.png/
Here's all the code that is relevant to the UITextView in the UITableViewController object:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[[NSNotificationCenter defaultCenter] addObserver: self
selector: #selector(keyboardWillShow:)
name: UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: #selector(keyboardWillHide:)
name: UIKeyboardWillHideNotification object:nil];
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
viewTargetedForEditing = (UIView *)textView;
return YES;
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
// shrink the textView to fit on-screen
originalTextViewFrame = textView.frame;
CGRect keyboardRect = [[keyboardUserinfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = keyboardRect.size.height;
CGRect newViewFrame = textView.frame;
CGFloat spaceAboveKeyboard = self.containerView.frame.size.height - keyboardHeight;
newViewFrame.size.height = (spaceAboveKeyboard < textView.frame.size.height) ? spaceAboveKeyboard : textView.frame.size.height;
/* animate the calculations */
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:[[keyboardUserinfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
textView.frame = newViewFrame;
[UIView commitAnimations];
// recalculate the keyboard height, in case we aren't in portrait mode
CGFloat toolbarHeight;
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
toolbarHeight = 44.0;
} else {
toolbarHeight = 32.0;
}
CGRect frame = textView.inputAccessoryView.frame;
frame.size.height = toolbarHeight;
}
- (void)endTextViewEditing
{
[viewTargetedForEditing resignFirstResponder];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
#pragma mark - Keyboard Notifications
- (void)keyboardWillShow:(NSNotification *)notification
{
[keyboardUserinfo release];
keyboardUserinfo = [[notification userInfo] retain];
[self viewDidBeginEditing:viewTargetedForEditing];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
[keyboardUserinfo release];
keyboardUserinfo = [[notification userInfo] retain];
[self viewDidEndEditing:viewTargetedForEditing];
}
- (void)viewDidBeginEditing:(id)aView
{
// called 2nd
UITableViewCell *cell = (UITableViewCell *)[aView superview];
[self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
- (void)viewDidEndEditing:(id)aView
{
NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[viewTargetedForEditing superview]];
gallupAppDelegate *appDelegate = (gallupAppDelegate *)[[UIApplication sharedApplication] delegate];
switch (indexPath.section) {
case SectionDescription:
if (![[(UITextField *)aView text] isEqualToString:self.plan.Description]) {
self.plan.Description = [(UITextField *)aView text];
[appDelegate saveManagedContext];
}
break;
case SectionNotes:
if (![[(UITextView *)aView text] isEqualToString:self.plan.Notes]) {
self.plan.Notes = [(UITextView *)aView text];
[appDelegate saveManagedContext];
}
break;
case SectionLocation:
if (![[(UITextField *)aView text] isEqualToString:self.plan.Location]) {
self.plan.Location = [(UITextField *)aView text];
[appDelegate saveManagedContext];
}
break;
}
}
The TextViewCell is a subclass of UITableViewCell, and it is the cell that is giving me the problem with scrolling.Here's the implementation:
#implementation TextViewCell
#synthesize contents=_contents;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
_contents = [[UITextView alloc] initWithFrame:CGRectZero];
[self addSubview:_contents];
self.contents.font = [UIFont systemFontOfSize:17];
self.contents.dataDetectorTypes = UIDataDetectorTypeAll;
CGRect frame = CGRectMake(0, 0, self.window.frame.size.width, 44.0);
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:self action:#selector(endTextViewEditing)];
UIToolbar *textViewToolbar = [[UIToolbar alloc] initWithFrame:frame];
textViewToolbar.barStyle = UIBarStyleBlackOpaque;
[textViewToolbar setItems:[NSArray arrayWithObjects:spacer, done, nil]];
self.contents.inputAccessoryView = textViewToolbar;
}
return self;
}
- (void)endTextViewEditing
{
[self.contents resignFirstResponder];
}
#define LEFT_MARGIN 15
#define TOP_MARGIN 5
- (void)layoutSubviews
{
[super layoutSubviews];
CGFloat width = self.frame.size.width - (LEFT_MARGIN *2);
CGFloat height = self.frame.size.height - (TOP_MARGIN *2);
self.contents.frame = CGRectMake(LEFT_MARGIN, TOP_MARGIN, width, height);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
//[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dealloc
{
[super dealloc];
}
#end
As it turns out, subclassing the UITableView and implementing the following fixed the problem:
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
{
[super setContentOffset:contentOffset animated:animated];
return;
static int i = 0;
if (0 == i) {
i++;
} else {
i = 0;
[super setContentOffset:contentOffset animated:animated];
}
return;
}
Apparently the -setContentOffset:animated: message was sent 2x, and if the first one is allowed to run the second time round doesn't do it's job properly.
Does anyone have any insite as to why this would fix the problem?

How to Add A Picker when selecting multiple textfield , I already One TextField working?

I Already have three TextField Outlet connected on my Nib File
IBOutlet UITextField *myTextField;
IBOutlet UITextField *myTextFieldd;
IBOutlet UITextField *myTextFields;
Now I am Trying To Add a Picker to Pop Out when you select myTextFieldd and myTextFields, notice that myTextField Works Great. I Also am Trying to Use the Same Picker to POP Up for the Three TextFields.
Code:
#import "PickrAppViewController.h"
#implementation PickrAppViewController
#synthesize categoryArray,selectedCategory;
- (void)viewDidLoad {
[super viewDidLoad];
categoryArray = [[NSMutableArray alloc] initWithObjects:#"Jack",#"Jone",nil];
}
-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == myTextField)
{
[numberTextField resignFirstResponder];
if([myTextField.text isEqualToString:#""]){
myTextField.text = [self.categoryArray objectAtIndex:0];
}
NSInteger pickerRow;
for(NSInteger i = 0; i < [self.categoryArray count]; i++){
NSString *string = [self.categoryArray objectAtIndex:i];
if([string isEqualToString:myTextField.text]){
pickerRow = i;
break; //Once we have it break out of the loop
}
}
[picker selectRow:pickerRow inComponent:0 animated:NO];
pickrView.frame = CGRectMake(0, 500, pickrView.frame.size.width, pickrView.frame.size.height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.50];
[UIView setAnimationDelegate:self];
pickrView.frame = CGRectMake(0, 300, pickrView.frame.size.width, pickrView.frame.size.height);
[self.view addSubview:pickrView];
[UIView commitAnimations];
return NO;
}
if([pickrView superview]){
[self animationForPickrDown];
}
return YES;
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if([pickrView superview]){
[self animationForPickrDown];
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark
#pragma mark PickrView datasource methods
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
self.selectedCategory = [NSString stringWithFormat:#"%#",[categoryArray objectAtIndex:row]];
myTextField.text = self.selectedCategory;
[self animationForPickrDown];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component
{
return [self.categoryArray count];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [self.categoryArray objectAtIndex:row];
}
- (void) animationForPickrDown
{
[UIView beginAnimations:nil context:NULL];
pickrView.frame = CGRectMake(0, 300, pickrView.frame.size.width, pickrView.frame.size.height);
[UIView setAnimationDuration:.50];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(stopAnimation)];
pickrView.frame = CGRectMake(0, 500, pickrView.frame.size.width, pickrView.frame.size.height);
[UIView commitAnimations];
}
- (void) stopAnimation
{
if([pickrView superview]){
[pickrView removeFromSuperview];
}
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
[myTextField release];
[pickrView release];
[selectedCategory release];
}
#end
Thank You
set delegate for other textfields and then remove condition if(textField == myTextField).
and
remove
if([pickrView superview]){
[self animationForPickrDown];
}
return YES;

Popping View crashes Application at [super dealloc]

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];
}
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.
Instead of:
[self.answerText release];
[self.titleLabel release];
[self.question release];
use:
self.answerText = nil;
self.titleLabel = nil;
self.question = nil;
or:
[answerText release]; answerText = nil;
[titleLabel release]; titleLabel = nil;
[question release]; question = nil;