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"]];
}
Related
I have 1 tabbarcontroller have Login and Complete Tab. I want to click on Logout button in LoginTab, all data and tableview in COmplete tab is reset. I used this code but it not work:
In CompleteTab.m:
-(void) viewDidLoad
{
temp = [[NSMutableArray alloc] init];
iduploadArray= [[NSMutableArray alloc] init];
FileCompletedArray = [[NSMutableArray alloc] init];
DiffArr= [[NSMutableArray alloc] init];
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
tableData = [[NSArray alloc] initWithObjects:FileCompletedArray,nil];
// [_tableView setAllowsSelection:YES];
//tableView.dataSource = self;
// [self.view addSubview:tableView];
// [self parseXMLFile:#"x"];
NSURL *url1 = [NSURL URLWithString:#"server.com"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL: url1] ;
....
temp = [FileCompletedArray mutableCopy];
_tableView.dataSource = self;
_tableView.delegate=self;
[self.view addSubview:_tableView];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"error: %#", error);//: %#", operation.responseString);
}
];
[httpClient enqueueHTTPRequestOperation:operation];
}
-(void) resetAll
{
[temp removeAllObjects];
[FileCompletedArray removeAllObjects];
[DiffArr removeAllObjects];
[_tableView reloadData];
}
In LoginTab.m:
- (IBAction)LogoutButton:(id)sender {
login = false;
username.hidden = NO;
pass.hidden = NO;
LoginButton.hidden = NO;
LogoutButton.hidden = YES;
//make all the arrays get reset
username.text =#"";
pass.text = #"";
[completeview resetAll];
}
I debug: when I click on Logout button,it called resetAll() function but each variable is 0x000000. So it cannot reset data and reload tableview. Can you help me? Thanks
Since the logout button is in loginTab, it doesnot have any reference to your completeTab. So you need to keep the completeTab reference some where in your app. Best choice is in appDelegate. Then on logout button click, take this instance and reset all data.
Keep your completab view controller instance in AppDelegate like this
#property (nonatomic, retain) UIViewController *completeTab;
self.completeTab = \\Your complete tab viewcontroller instance.
Then on logout button click
[(AppDelegate *)[[UIApplication sharedApplication] delegate].completTab resetAll]
Hope this helps.
Use the selector to call the reset method like this
[completeview performSelector:#selector(resetAll)];
Please create sample project with Tabbased Application.
====== AppDelegate.m ======
#import "LoginTab.h"
#import "CompleteTab.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1 = [[[LoginTab alloc] initWithNibName:#"LoginTab" bundle:nil] autorelease];
UIViewController *viewController2 = [[[CompleteTab alloc] initWithNibName:#"CompleteTab" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
#end
====== LoginTab.m ======
#implementation LoginTab
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"LoginTab", #"LoginTab");
self.tabBarItem.image = [UIImage imageNamed:#"LoginTab"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)LogoutButton:(id)sender {
// Post Notification to CompleteTab Class
[[NSNotificationCenter defaultCenter]
postNotificationName:#"resetAll"
object:self];
}
====== CompleteTab.m ======
#implementation CompleteTab
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"CompleteTab", #"CompleteTab");
self.tabBarItem.image = [UIImage imageNamed:#"CompleteTab"];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(resetAll:)
name:#"resetAll"
object:nil];
return self;
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void) resetAll:(NSNotification *) notification
{
NSLog(#"Reset All Called");
}
I am able to call resetAll method of CompeteTab using NSNotification Concept. Please follow this code.
I'd also recommend you check out the free Sensible TableView framework as it has such restting functionality out of box.
As for the method [tableView reloadData] : The table view's delegate or data source calls this method when it wants the table view to completely reload its data. It should not be called in the methods that insert or delete rows, especially within a block implemented with calls to beginUpdates and endUpdates.
I believe you are calling the reloadData in resetAll which is updating the FileCompletedArray which provides the dataSource for the table. Can you call it from somewhere else.
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.
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
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.
i create i navigationController project name:autoload,
then create two uiviewContorller named: second,three
i want the process is load rootView the load second in method:"viewDidLoad" then auto load three in method"viewdidload",
here is the code:
rootView:
- (void)viewDidLoad {
self.title = #"first";
Second *second = [[Second alloc] init];
AutoLoadAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:second animated:YES];
[super viewDidLoad];
}
second:
- (void)viewDidLoad {
self.title = #"second";
[super viewDidLoad];
}
now build an go the program, i can auto load to second very correct
includeing the title content and also the navgation button
then i want aotoload three in second,so add the code in second method:"viewdidload"
second:
- (void)viewDidLoad {
self.title = #"second";
**Three *three = [[Three alloc] init];
AutoLoadAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:three animated:YES];**
[super viewDidLoad];
}
finaly add the title to three:
three:
- (void)viewDidLoad {
self.title = #"three";
[super viewDidLoad];
}
then build and go, you will find that the content is right "three"
but the title is wrong "second", it should be "three"
and you will also find the navgation button is wrong
what's wrong with my that,what i should do to implement the program of autoload to three?
note:
i try that :
if i add a button in second and move the code
Three *three = [[Three alloc] init];
AutoLoadAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:three animated:YES];
to the ibaction ,it will be work correct, but i want it load automaticly
Instead of calling pushViewController in the viewDidLoad methods, try setting the viewControllers array in the applicationDidFinishLaunching method:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
RootViewController *root = [[RootViewController alloc] init];
root.title = #"root";
Second *second = [[Second alloc] init];
second.title = #"second";
Three *three = [[Three alloc] init];
three.title = #"three";
[navigationController setViewControllers:[NSArray arrayWithObjects:root,second,three,nil] animated:YES];
[root release];
[second release];
[three release];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}