Why does my TTTableViewController not appear - iphone

I have an application which contains a scrollview with two subviews (to scroll left and right between them)
Both views appear correctly and scrolling between the views worked fine. Now I want to change the first view to be a TTTableView (courtesy of Three20) but when I use the class 'TableControlsTestController' from the TTCatalog application all I see is an empty tableView
Note that this class contains all the data to display 6 cells
To add the new TTTableView I use the following
[scrollView addSubview:detailView.view];
where detailView is the instance of TableControlsTestController
To try and narrow down where the problem is I also tried calling
[self presentModalViewController:detailView animated:YES];
This correctly displays the tableview with the 6 cells.
Why when I try to add the view to the scrollView does this not work as I expect?
For reference if you do not have access to the TTCatalog
#import "TableControlsTestController.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
#implementation TableControlsTestController
///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject
- (id)init {
if (self = [super init]) {
self.tableViewStyle = UITableViewStyleGrouped;
self.autoresizesForKeyboard = YES;
self.variableHeightRows = YES;
UITextField* textField = [[[UITextField alloc] init] autorelease];
textField.placeholder = #"UITextField";
textField.font = TTSTYLEVAR(font);
UITextField* textField2 = [[[UITextField alloc] init] autorelease];
textField2.font = TTSTYLEVAR(font);
textField2.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
TTTableControlItem* textFieldItem = [TTTableControlItem itemWithCaption:#"TTTableControlItem"
control:textField2];
UITextView* textView = [[[UITextView alloc] init] autorelease];
textView.text = #"UITextView";
textView.font = TTSTYLEVAR(font);
TTTextEditor* editor = [[[TTTextEditor alloc] init] autorelease];
editor.font = TTSTYLEVAR(font);
editor.backgroundColor = TTSTYLEVAR(backgroundColor);
editor.autoresizesToText = NO;
editor.minNumberOfLines = 3;
editor.placeholder = #"TTTextEditor";
UISwitch* switchy = [[[UISwitch alloc] init] autorelease];
TTTableControlItem* switchItem = [TTTableControlItem itemWithCaption:#"UISwitch" control:switchy];
UISlider* slider = [[[UISlider alloc] init] autorelease];
TTTableControlItem* sliderItem = [TTTableControlItem itemWithCaption:#"UISlider" control:slider];
self.dataSource = [TTListDataSource dataSourceWithObjects:
textField,
editor,
textView,
textFieldItem,
switchItem,
sliderItem,
nil];
}
return self;
}
#end

It turns out that some of the events were not being propagated through the scrollView and therefore not handled in the TTTableViewController. To fix this I had to do the following in my scrollView
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[myNewTTViewController viewWillAppear:NO];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[myNewTTViewController viewDidAppear:NO];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[myNewTTViewController viewWillDisappear:NO];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[myNewTTViewController viewDidDisappear:NO];
}
As soon as I did this the table popped into life

Related

Viewdid load method call on popview

In my application i set some animations in View1's view load() ,At first launch its working propely,if im pushed into otherview ,and while pop into view1 its not animating,What shoud i do for animate while pop view from other view?here my view did load code,
- (void)viewDidLoad
{
artext=[[NSMutableArray alloc] init];
arimage=[[NSMutableArray alloc] init];
arsound=[[NSMutableArray alloc] init];
[super viewDidLoad];
[self copysqlitetodocuments];
[self Readthesqlitefile];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"classroom.png"]];
}
i tried with
- (void)viewDidAppear:(BOOL)animated
{
[self buttonmover];
[super viewDidAppear:animated];
}
its not working,Can any one pls help me to solve this problem
If you want to execute code when the view appears (e.g. an animation), -viewDidLoad is the wrong place to do it.
You should probably use:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// ...
}
Try in viewWillAppear
-(void)viewWillAppear:(BOOL)animated
{
artext=[[NSMutableArray alloc] init];
arimage=[[NSMutableArray alloc] init];
arsound=[[NSMutableArray alloc] init];
[self copysqlitetodocuments];
[self Readthesqlitefile];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"classroom.png"]];
}
When your viewDidLoad method is called, the controller isn't yet in the view hierarchy, so the animations doesn't work.
You have to perform animations in viewWillApper, after implementing the method [super viewWillAppear]. Something like:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
artext = [[NSMutableArray alloc] init];
arimage = [[NSMutableArray alloc] init];
arsound = [[NSMutableArray alloc] init];
[self copysqlitetodocuments];
[self Readthesqlitefile];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"classroom.png"]];
}

UITabBarController's TabBar is slightly hidden

My UITabBarController's tabBar is slightly off the view, please can you tell me what is wrong with my code:
LoggedInViewController *lvc = [[[LoggedInViewController alloc]
initWithAccount:account] autorelease];
[self presentModalViewController:lvc animated:YES];
- (void)viewDidLoad
{
self.tabController = [[UITabBarController alloc] init];
LoggedInFeedNavigationController *navController;
navController = [[LoggedInFeedNavigationController alloc]
initWithAccount:self.account];
[self.tabController setViewControllers:
[NSArray arrayWithObject:navController]];
[self.view addSubview:self.tabController.view];
[super viewDidLoad];
}
You are adding the tabController view as a subview, but you have not specified where it should be located within its parent view, or how it should be resized when the parent view changes size. Try the following:
- (void)viewDidLoad
{
[super viewDidLoad]; // see note
self.tabController = [[UITabBarController alloc] init];
LoggedInFeedNavigationController *navController;
navController = [[LoggedInFeedNavigationController alloc]
initWithAccount:self.account];
[self.tabController setViewControllers:
[NSArray arrayWithObject:navController]];
UIView *tabView = self.tabController.view;
[self.view addSubview:tabView];
tabView.frame = self.view.bounds;
tabView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
}
Note: you are not required to call [super viewDidLoad], but if you do decide to call it, you should call it at the beginning of your viewDidLoad method, and not at the end.

how we create textField in clicking UIBarButton "add"

- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(add:)] autorelease];
}
-(IBAction) add :(id)sender {
}
in view textfield not find the trick is when I click the add textfiled appears in view
You could create the textfield ahead of time add it to your view and set the hidden property to YES and in add you just make it visible by setting hidden to NO.
- (void)loadView
{
UIView * newView = [[UIView alloc] init];
// retaining property
self.myTextField = [[[UITextField alloc] init] autorelease];
myTextField.hidden = YES;
[newView addSubview:myTextField];
self.view = newView;
[newView release];
}
- (IBAction)add:(id)sender
{
myTextField.hidden = NO;
}
Adding a new UITextField every time add is called
- (IBAction)add:(id)sender
{
UITextField * textfieldToAdd = [[[UITextField alloc] init] autorelease];
// ... configuration code for textfield ...
[self.view addSubview:textfieldToAdd];
}

UIView drawRect vs initWithFrame

I have a UIView which has several buttons added to it as subviews. Currently I have the buttons in drawRect:, which I have heard is a bad idea because drawRect can be called several times. I tried to move these UIButtons to initWithFrame, but they just don't get drawn. How should I fix this?
I am not using interface builder, so there are no NIB files present. The initWithFrame is called. I checked by adding an NSLog(...), and my NSMutableArrays are being properly initialized.
My initWitFrame: code currently has very little. It is
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
results = [[NSMutableArray alloc] init];
inputs = [[NSMutableArray alloc] init];
format = [[NSDateFormatter alloc] init];
[format setDateFormat:#"EEE, MMM dd, yyyy"];
renc =[[RenameController alloc] init];
}
return self;
}
I have tried to add a textlabel like the following
#define BOX_WIDTH 155.0
#define BOX_OFFSET 45.00
#define ROW_HEIGHT 27
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
results = [[NSMutableArray alloc] init];
inputs = [[NSMutableArray alloc] init];
format = [[NSDateFormatter alloc] init];
[format setDateFormat:#"EEE, MMM dd, yyyy"];
renc =[[RenameController alloc] init];
double row=0.0;
[self makelabel:#"Start" at:CGRectMake(0, row, BOX_OFFSET, ROW_HEIGHT)];
}
return self;
}
-(void) makelabel:(NSString *) str at:(CGRect) rect
{
UILabel *title = [[UILabel alloc] initWithFrame:rect];
title.text = str;
title.textAlignment = UITextAlignmentLeft;
title.textColor = [UIColor blackColor];
title.backgroundColor = [UIColor clearColor];
title.font = [UIFont boldSystemFontOfSize:FONT_SIZE];
[self addSubview:title];
[title release];
}
#tonklon is spot on. Additionally, the usual pattern is to have your custom initialization code in a third method, such as -sharedInit, which is called after the appropriate super initializer:
- (id)sharedInit {
// do whatever, possibly releasing self on error and returning nil
return self;
}
- (id)initWithFrame: (CGRect)frame {
self = [super initWithFrame: frame];
if (self) {
self = [self sharedInit];
}
return self;
}
- (id)initWithCoder: (NSCoder *)aDecoder {
self = [super initWithDecoder: aDecoder];
if (self) {
self = [self sharedInit];
}
return self;
}
I bet the view is loaded from a nib file? Just use the same code to add your subviews in initWithCoder:
UIView Class Reference:
If you use Interface Builder to design
your interface, this method is not
called when your view objects are
subsequently loaded from the nib file.
Objects in a nib file are
reconstituted and then initialized
using their initWithCoder: method,
which modifies the attributes of the
view to match the attributes stored in
the nib file. For detailed information
about how views are loaded from a nib
file, see Resource Programming Guide.

UITextField resignFirstResponder not working?

I've double checked all the connections in the nib file. My code -
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"iphone_bg_login.png"]];
self.title = #"Login screen";
loginTxt = [[UITextField alloc] init];
pwdText = [[UITextField alloc] init];
loginFailedTxt = [[UILabel alloc] init];
loginBtn = [[UIButton alloc] init];
navAppDelegate = (NavAppDelegate *)[[UIApplication sharedApplication] delegate];
navAppDelegate.navController.navigationBarHidden = YES;
//NSArray *subVs = (NSArray *) [self.view subviews];
[super viewDidLoad];
}
I've used a subclass of UIView (UIControl) and added all the UI elements to it in the Interface builder.The UIControl's touchDown method is connected to backgroundTap method.
-(IBAction) backgroundTap:(id) sender {
[loginTxt resignFirstResponder];
[pwdText resignFirstResponder];
//[[UIApplication sharedApplication] becomeFirstResponder];
//[sender resignFirstResponder];
}
So the keyboard isn't removed like it's supposed to. Not sure why.
Thanks for the help!
Teja.
DyingCactus has pointed to your error. You're replacing the NIB-version of the control with a completely different control, losing your pointer to the one in the NIB. When you call resignFirstResponder, you're calling it on your duplicate object, not the one that's actually on the screen. Get rid of the alloc and init calls for things wired in the NIB.