I have many view controller when i click on tableView cell it move to new view controller problem is that it takes alot of time to move to the next view may be due to view which is to load fetches data from server here is my code for the view which loads
- (void)viewDidLoad {
appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
UIImageView *bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Nav.png"]];
[bottomImageView setFrame:CGRectMake(0,690,1024,34)];
[self.view addSubview:bottomImageView];
UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(10.0, 2.0, 88, 40.0)];
[button1 addTarget:self action:#selector(loginPressed) forControlEvents:UIControlEventTouchUpInside];
[button1 setImage:[UIImage imageNamed:#"logoutN.png"] forState:UIControlStateNormal];
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithCustomView:button1];
self.navigationItem.rightBarButtonItem = button;
self.title=#"Catalog";
popImageView.hidden=YES;
passwordLabel.hidden=YES;
userLabel.hidden=YES;
userNameTextField.hidden=YES;
userPasswordTextField.hidden=YES;
signInButton.hidden=YES;
tableView.hidden=NO;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRow = YES;
if(!categoryArray){
categoryArray =[[NSMutableArray alloc] init];
}
if(!userArray){
userArray =[[NSMutableArray alloc] init];
}
if(!subCategoryArray){
subCategoryArray =[[NSMutableArray alloc] init];
}
if(!subCategoryArrayOne){
subCategoryArrayOne =[[NSMutableArray alloc] init];
}
if(!subCategoryArrayTwo){
subCategoryArrayTwo =[[NSMutableArray alloc] init];
}
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
int count=[appDelegate.coffeeArray count];
NSLog(#"Arrays Content Are %d",count);
tableView.backgroundView = nil;
[super viewDidLoad];
}
is there any way so that view loads fast
Your view is not loading fast because of I guess those data set operation in viewDidLoad method . I think those are :
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
The one thing you could do is to move this operations to perform on the background thread . For that move this operations to the separate function and call that to perform on background from the view did load method :
-(void)dataOperations
{
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
}
and in viewDidLoad call this function in background:
[self performSelectorInBackground:#selector(dataOperations) withObject:nil];
Or you can directly call those method from viewDidLoad like :
[self performSelectorInBackground:#selector(setUpData) withObject:nil];
Related
I can't figure out how did this happened.But there is something i have done may cause it.
1,I have swizzled viewDidLoad & viewDidAppear in UIViewController.
2,The AppDelegate's window's rootViewController is a mainViewController(UIViewController).
And I add customNavigationController.view to mainViewController.view.
CustomNavigationController's rootViewController is a UITabbarController.
3,Thread problem?
4,This happened randomly when i tap and pan on the screen frequently.
Here is My code :
In my Custom UITabBarController
- (void)loadViewControllers {
HomeViewController *homeVC = [[HomeViewController alloc] init];
[homeVC.tabBarItem setImage:[UIImage imageNamed:#"Home"]];
[homeVC.tabBarItem setTitle:homeTab];
ProductsViewController *productsVC = [[ProductsViewController alloc] init];
[productsVC.tabBarItem setImage:[UIImage imageNamed:#"Products"]];
[productsVC.tabBarItem setTitle:productsTab];
DiscoverViewController *discoverVC = [[DiscoverViewController alloc] init];
[discoverVC.tabBarItem setImage:[UIImage imageNamed:#"Discover"]];
[discoverVC.tabBarItem setTitle:discoverTab];
AssetsMainViewController *assetsVC = [[AssetsMainViewController alloc] init];
[assetsVC.tabBarItem setImage:[UIImage imageNamed:#"Assets"]];
[assetsVC.tabBarItem setTitle:assetsTab];
NewsViewController *newsVC = [[NewsViewController alloc] init];
[newsVC.tabBarItem setImage:[UIImage imageNamed:#"News"]];
[newsVC.tabBarItem setTitle:newsTab];
[self setViewControllers:#[homeVC,productsVC, discoverVC, assetsVC, newsVC]];
}
In mainViewController:
- (void)loadViewController {
TJSNavigationController *rootNavi = [[TJSNavigationController alloc] initWithRootViewController:[TJSTabBarController sharedSingleton]];
[rootNavi.view setFrame:CGRectMake(0, 0, tMeasure_Width_Sreen, tMeasure_Height_Screen)];
[self.view addSubview:rootNavi.view];
[[TJSTabBarController sharedSingleton] loadViewControllers];
[[TJSTabBarController sharedSingleton] setDelegate:self];
}
I have a UInavigationController stack. In the RootViewController i have button . When i click the button a new viewcontroller is pushed and UIDatePicker should be shown . the problem is when navigating to view controller the date picker is shown for 1 sec and then suddenly disappeared and the whole screen goes Black. Here is the code
//rootviewcontroller
- (IBAction)dateAction:(id)sender
{
self.another = [[AnotherViewController alloc]initWithButtonWithTag:self.dateButton.tag andDelegate:self];
[self.navigationController pushViewController:self.another animated:YES];
self.another.navigationItem.title = #"DateName";
}
//second viewcontroller
- (void)viewDidload
{
self.pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 250, 325, 300)];
[self.pickerView addTarget:self action:#selector(datePickerDidChangeDate:) forControlEvents:UIControlEventValueChanged];
self.pickerView.datePickerMode = UIDatePickerModeDate;
self.pickerView.hidden = NO;
self.pickerView.date = [NSDate date];
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateStyle = NSDateFormatterLongStyle;
[self.view addSubview:self.pickerView];
}
A help would be appreciated
try this codeā¦
first view controller
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *temp=[NSArray arrayWithObjects:#"button1" ,#"button2" ,#"button3",nil];
for (int i=0; i<=2; i++)
{
_likeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[_likeBtn setFrame:CGRectMake(20+(i*80), 220, 102, 20 )];
[_likeBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[_likeBtn setTitle:[temp objectAtIndex:i] forState:UIControlStateNormal];
[_likeBtn addTarget:self action:#selector(action:) forControlEvents:UIControlEventTouchUpInside];
[_likeBtn setTag:i];
[self.view addSubview:_likeBtn];
}
// Do any additional setup after loading the view from its nib.
}
- (IBAction)action:(id)sender
{
UIButton *button=(UIButton *)sender;
NSLog(#"%d",button.tag);
secViewController *obj = [[secViewController alloc]init];
obj.tagValue=button.tag;
[self.navigationController pushViewController:obj animated:YES];
obj.navigationItem.title = #"DateName";
}
second view .h file
#property(nonatomic,assign) NSInteger *tagValue;
.m file
- (void)viewDidLoad
{
[super viewDidLoad];
NSInteger *tag=self.tagValue;
if (tag==0)
{
//tableView
NSLog(#"tableview");
}
else
{
//datepicker
NSLog(#"picker");
self.pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 250, 325, 300)];
[self.pickerView addTarget:self action:#selector(datePickerDidChangeDate:) forControlEvents:UIControlEventValueChanged];
self.pickerView.datePickerMode = UIDatePickerModeDate;
self.pickerView.hidden = NO;
self.pickerView.date = [NSDate date];
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateStyle = NSDateFormatterLongStyle;
[self.view addSubview:self.pickerView];
}
// Do any additional setup after loading the view from its nib.
}
-(void)datePickerDidChangeDate:(id)sender
{
NSLog(#"%#",self.pickerView.date);
}
let me know statisfied or not...
i have asked this question here also but i didn't get any solution.so i am asking here again with the full explanation.
I downloaded EPub Reader library from here. When i run this library,first comes a table view which contain four rows having values EPUB ,PDF etc and after clicking on the "EPUB" row
book appears successfully with the top toolbar. Because i have to load the book first in start instead of showing the toolbar i did some changes with the code. copied some code from didSelectRowAtIndexPath and added that code into delegate.m. so now the problem is book is successfully loading but the toolbar is not showing up
here is my code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [userDefaults objectForKey:#"AppleLanguages"];
EPubViewController *epubView = [[EPubViewController alloc] init];
[epubView loadEpub:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"AtoZbook" ofType:#"epub"]]];
self.navigationController = [[UINavigationController alloc]initWithRootViewController:epubView];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
the code of loading epubView was in RootViewController.m in the original library
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
//TXT
case 0:{
//txt
}
break;
//PDF
case 1:{
//PDF
}
break;
//EPUB
case 2:{
epubView = [[EPubViewController alloc] init];
[epubView loadEpub:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"The Chessmen of Mars" ofType:#"epub"]]];
epubView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:epubView animated:YES];
[epubView release];
}
break;
case 3:{
//another book
}
break;
default:
break;
}
}
here is my view didLoadMethod of EpubViewController
- (void)viewDidLoad {
[super viewDidLoad];
loadingIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
loadingIndicator.center = CGPointMake(toolbar.frame.size.width/2 ,toolbar.frame.size.height/2);
[loadingIndicator startAnimating];
toolbar.alpha = 0.8;
[self.toolbar addSubview:loadingIndicator];
[webView setDelegate:self];
UIScrollView* sv = nil;
for (UIView* v in webView.subviews) {
if([v isKindOfClass:[UIScrollView class]]){
sv = (UIScrollView*) v;
sv.scrollEnabled = NO;
sv.bounces = NO;
}
}
currentTextSize = 100;
//Webview
UISwipeGestureRecognizer* rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(gotoNextPage)] ;
[rightSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
UISwipeGestureRecognizer* leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(gotoPrevPage)] ;
[leftSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[webView addGestureRecognizer:rightSwipeRecognizer];
[webView addGestureRecognizer:leftSwipeRecognizer];
[self performSelector:#selector(stratRolling)];
}
here are the images
i want to say again that the toolbar works fine when i show the epubViewController from the Case 2 i mean by clicking the row if i have to show the table view first.
your tool bar is hiding being navigation bar since navigation bar is always on top you can add your tool bar as sub view of navigation bar i m not sure if it will work though best approch is use navigation bar and add item it it like left button right button and title stuff or you can add a view as subview of navigation bar i have done that before sample code
navBar=self.navigationController.navigationBar;
[navBar addSubview:statusBar];
statusBar.frame=f;
self.navigationController.navigationBar.translucent = YES;
here statusBar was a view was set up like your tool bar same size.
I want my whole project to run in portrait mode only and only the view that's for viewing the photo's can turn on landscape same as if using the facebook (we view photo's they turn landscape also but other view's remains in portrait) i want to know that how it's done as i have a table view that has images that i get from the DB from the server and every particular data contains different number's of photo's so now i want that after the user select's the photo's they should open up fully and can be viewed in landscape and in portrait as well i did tried
I am working with ios6
- (BOOL)shouldAutorotate
{
return NO;
}
implementing in all the view's so that they can remain in portrait but still they turn in landscape how should i restrict it and please can any one tell me that in one of my class i have images in table view(loaded from the DB) and i have another class that open's up the selected photo from the table
My PhotoView.m class
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dic = [photos objectAtIndex:indexPath.row];
NSLog(#" *** url is %#",[dic objectForKey:#"url"]);
[self.delegate showPhotoAtUrl:[dic objectForKey:#"url"]];
}
My PhotoViewController.h class
#import <UIKit/UIKit.h>
#interface PhotoViewController : UIViewController <UIScrollViewDelegate>
{
NSString *url;
UIButton *doneButton;
}
#property (nonatomic, retain) UIImageView *imageView;
- (id) initWithPhotoUrl:(NSString *)photoUrl;
#end
and PhotoViewController.m class
#import "PhotoViewController.h"
#interface PhotoViewController ()
#end
#implementation PhotoViewController
#synthesize imageView;
- (id) initWithPhotoUrl:(NSString *)photoUrl
{
self = [super init];
if(self) {
url = [photoUrl retain];
}
return self;
}
- (void)dealloc
{
[url release];
self.imageView = nil;
[doneButton release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.tag = 1;
spinner.center = self.view.center;
[spinner startAnimating];
[self.view addSubview:spinner];
[spinner release];
[self performSelectorInBackground:#selector(loadPhotoData) withObject:nil];
doneButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[doneButton addTarget:self action:#selector(doneTouched) forControlEvents:UIControlEventTouchUpInside];
[doneButton setTitle:#"done" forState:UIControlStateNormal];
[doneButton setBackgroundColor:[UIColor clearColor]];
doneButton.frame = CGRectMake(2, 2, 60, 30);
[self.view addSubview:doneButton];
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.title = #"";
self.navigationController.navigationBarHidden = YES;
}
- (void) doneTouched
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void) loadComplete:(NSData *)imageData
{
if(!imageData) return;
UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)[self.view viewWithTag:1];
if(spinner) {
[spinner stopAnimating];
[spinner removeFromSuperview];
}
UIImage *img = [UIImage imageWithData:imageData];
float scale = MIN(self.view.frame.size.width/img.size.width, self.view.frame.size.height/img.size.height);
self.imageView = [[[UIImageView alloc] initWithImage:img] autorelease];
self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width*scale, self.imageView.image.size.height*scale);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.imageView.center = scrollView.center;
scrollView.delegate = self;
scrollView.contentSize = self.imageView.frame.size;
scrollView.minimumZoomScale = 1;
scrollView.maximumZoomScale = 2;
[scrollView addSubview:self.imageView];
[self.view addSubview:scrollView];
[scrollView release];
[self.view bringSubviewToFront:doneButton];
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
- (void) loadPhotoData
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
[self performSelectorOnMainThread:#selector(loadComplete:) withObject:imageData waitUntilDone:NO];
[pool drain];
}
#end
and in the main class i have have this method that calls the PhotoViewController to load the selected photo
- (void) showPhotoAtUrl:(NSString *)url
{
PhotoViewController *vc = [[PhotoViewController alloc] initWithPhotoUrl:url];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
}
Now my problem is how should i get the images after getting selected from the table to be open up in the same type of the view that open's up in FB app (open's the selected photo in portrait/landscape compatible view) i am only able to get one photo in my PhotoViewController class can any one tell me how can i add all the photo's to the PhotoViewController class so that i get the effect that i want ?... Any code help will be very helpful .. Thanks in Advance for contributing your time
In Short i have two things to do :
I have to restrict my project to only portrait mode leaving only the photo's view to have landscape/portrait compatibility.
I am currently having the photo's in my table view that i want on selection to open up in the same style(landscape/portrait compatibile) as FB or other app's do while viewing the photo's.
These only work on iOS 6.0
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
The method will return which orientation mode to use first.
Below are supportedInterfaceOrientations:
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
For iOS > 4.0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Other ViewControllers will have
-(BOOL)shouldAutorotate { return NO; }
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation{
return NO;
}
Let me first state, that this is not a matter of getting my selector name right, nor setting up the button target in loadView, nor any other suggestion I've seen in the last 4 hours of browsing. I should also explain I am not using nibs, nor IB.
These buttons have been working for the bulk of development.
Then poof! It's not just the buttons. My table views do not scroll. Pressing the cells in the table views do not invoke the actions that I had setup.
It seems I've broken the responder chain entirely; or something to that effect.
To try and narrow down the source of the problem a created a window-based project; stripped out everything that xCode generates; deleted the nib; and copied in several methods from my original app delegate and my rootViewController.
It's the RVT that contains the subView that contains the buttons. Fairly straight forward. Same effect. I've literally stripped out all functional code but the following source in appDelegate.m:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] setDelegate:self];
if(window == nil)
window = [[UIWindow alloc] init];
window.autoresizesSubviews = YES;
if(controller == nil)
controller = [[Controller alloc] init];
window.rootViewController = controller;
[window makeKeyAndVisible];
return YES;
}
-(void)dealloc {
[window release];
[controller release];
[super dealloc];
}
And in Controller:
- (void)buttonResponse {
NSLog(#"Button touched up inside!!!!!");
}
- (void)loadView {
[super loadView];
//test
button = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Button" ofType:#"png"];
UIImage *image = [UIImage imageWithContentsOfFile:filePath];
CGSize imageSize = [image size];
CGRect buttonFrame = CGRectMake(0,0,imageSize.width + 100, BUTTONBAR_H + 100);
button.frame = buttonFrame;
[button setImage:image forState:UIControlStateNormal];
button.backgroundColor = [UIColor blueColor];
[button setTitle:#"" forState:UIControlStateNormal];
button.userInteractionEnabled = YES;
[button addTarget:self action:#selector(buttonResponse) forControlEvents: UIControlEventTouchUpInside];
UIView *view = self.view;
CGRect viewFrame = view.frame; //self.view is valid and takes up available screen
[self.view addSubview:button];
[self.view bringSubviewToFront:button];
//end test
[self.view setNeedsDisplay];
}
- (void)dealloc {
[button release];
[super dealloc];
}
I know it's gotta be something really simple. But I can't see it. I would prefer to leave my hair in place. I'm wondering if that's going to happen as I continue to learn the quirks.
Does loadView ever get called? Put a NSLog (or a breakpoint) in loadView just as a sanity check.
Also, from UIViewController Documentation:
If you override this method (loadView) in order to create your views manually,
you should do so and assign the root view of your hierarchy to the
view property. (The views you create should be unique
instances and should not be shared with any other view controller
object.) Your custom implementation of this method should not call super.
If you want to perform any additional initialization of your views, do
so in the viewDidLoad method. In iOS 3.0 and later, you
should also override the viewDidUnload method to release any
references to the view or its contents.
Try putting all the button code in viewDidLoad:
- (void)buttonResponse:(id)sender {
NSLog(#"Button touched up inside!!!!!");
}
- (void)loadView {
// Dont call super (according to the UIViewController docs)
// [super loadView];
// self.view = ... however your setting up self.view
// self.view.frame = CGRectMake....
// self.view.etc...
[self.view setNeedsDisplay];
}
- (void)viewDidLoad {
[super viewDidLoad];
button = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Button" ofType:#"png"];
UIImage *image = [UIImage imageWithContentsOfFile:filePath];
CGSize imageSize = [image size];
CGRect buttonFrame = CGRectMake(0,0,imageSize.width + 100, BUTTONBAR_H + 100);
button.frame = buttonFrame;
[button setImage:image forState:UIControlStateNormal];
button.backgroundColor = [UIColor blueColor];
[button setTitle:#"" forState:UIControlStateNormal];
button.userInteractionEnabled = YES;
[button addTarget:self action:#selector(buttonResponse:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[self.view bringSubviewToFront:button];
}
- (void)dealloc {
[button release];
[super dealloc];
}