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];
}
Related
I have a double-tap gesture on a view controller iRpImageViewerViewController (topmost on the navigation stack), and each time a view on iRpImageViewerViewController is double-tapped, it pushes a image editor view controller iRpImageEditorViewController onto the stack, that's why there are several of them, none of which appeared. Each time I double-tap, it's added, but never appears. self is simply the class that houses this double-tap gesture iRpImageViewerViewController, and does in fact have a navigationController per the LLDB output
po self.navigationController returns a navigation controller as expected.
po self.navigationController viewControllers shows a new view controller being added to the list with each pushViewController statement encountered, yet the pushed item won't show up on screen.
I shouldn't have to push and then move to front, right?? Doesn't the push automatically make it the frontmost view controller?
Note that my navigation controller is NOT the root controller in my hierarchy, starting from the window. I have a full screen map view controller, then a half-screen 'dashboard' view controller, then within that I have a window on the dashboard that has a picture, and that picture is itself a view controller. So starting with the picture view controller, shown here, you can walk through everything that happens
#implementation iRpDashboardHeaderImagesViewController
{
IGGridView *theGridViewControl;
UIView *theGridParentView;
iRpImageSet *thePropertyImageSet;
iRpDashboardViewController *dashboardViewController;
UIImageView *primaryImageMarker;
UINavigationController *imageEditorNavController;
iRpImageViewerViewController *imageViewerVC;
}
-(id)initWithParentViewController:(iRpDashboardViewController*)parentController
{
self = [super init];
if (self)
{
dashboardViewController = parentController;
}
return self;
}
-(void)loadView
{
// Just a basic size to get started... the final size is set later in another method. I believe actual height will be 220
CGRect theGridRectangle = CGRectMake(0, 0, 375, 220);
theGridViewControl = [[IGGridView alloc]initWithFrame:theGridRectangle style:IGGridViewStyleSingleCellPaging];
// Set additional properties to configure the grid view
theGridViewControl.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
theGridViewControl.selectionType = IGGridViewSelectionTypeCell;
theGridViewControl.contentMode = UIViewContentModeScaleAspectFit;
theGridViewControl.allowHorizontalBounce = NO;
theGridViewControl.alwaysBounceVertical = NO;
self.view = theGridViewControl;
}
-(void)viewDidLoad
{
[super viewDidLoad];
imageEditorNavController = [[UINavigationController alloc] init];
}
-(void)presentImageViewerForCellAtPath:(IGCellPath*)path
{
iRpImageAndMedia *imageAndMediaItem = [thePropertyImageSet objectAtIndex:path.columnIndex];
imageViewerVC = [[iRpImageViewerViewController alloc] initWithParentViewController:self imageSet:thePropertyImageSet initialImageAndMedia:imageAndMediaItem];
imageViewerVC.edgesForExtendedLayout = UIRectEdgeNone;
imageViewerVC.navigationItem.title = dashboardViewController.parcelNbr;
imageViewerVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(imageEditorDone)];
// Create a navigation controller to embed the image viewer view controller inside.
[imageEditorNavController pushViewController:imageViewerVC animated:YES];
[self presentViewController:imageEditorNavController animated:YES completion:^(void)
{
}];
}
-(void)imageEditorDone
{
[self dismissViewControllerAnimated:YES completion:^{}];
}
}
...
#implementation iRpImageViewerViewController
{
IGGridView *theMainImageGridviewControl;
iRpImageSet *thePropertyImageSet;
iRpImageFilmstripViewController *theFilmstripViewController;
iRpImageAndMedia *initialMediaItem;
UIImageView *primaryImageMarker;
iRpImageEditorViewController *imageEditorVC;
UIViewController *theParentViewController;
}
-(id)initWithParentViewController:(UIViewController*)parentViewController imageSet:(iRpImageSet*)imageSet initialImageAndMedia:(iRpImageAndMedia*)imageAndMedia
{
self = [super initWithNibName:#"iRpImageViewerViewController" bundle:nil];
if (self)
{
theParentViewController = parentViewController;
theFilmstripViewController = [[iRpImageFilmstripViewController alloc] initWithParentViewController:self imageSet:imageSet initialImageAndMedia:imageAndMedia];
initialMediaItem = imageAndMedia;
thePropertyImageSet = imageSet;
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
theMainImageGridviewControl = [[IGGridView alloc]initWithFrame:self.mainImagePlaceholderView.frame style:IGGridViewStyleSingleCellPaging];
// Set additional properties to configure the grid view
theMainImageGridviewControl.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
theMainImageGridviewControl.selectionType = IGGridViewSelectionTypeCell;
theMainImageGridviewControl.contentInset = UIEdgeInsetsZero;
theMainImageGridviewControl.allowHorizontalBounce = NO;
theMainImageGridviewControl.alwaysBounceHorizontal = NO;
theMainImageGridviewControl.alwaysBounceVertical = NO;
[self.mainImagePlaceholderView addSubview:theMainImageGridviewControl];
[self addAChildViewController:theFilmstripViewController toViewWithTag:self.filmstripPlaceholderView.tag];
}
-(void)addGestureRecognizersToCell:(IGGridViewImageCell*)cell
{
static NSMutableArray *recognizers;
UITapGestureRecognizer *doubleTapRecognizer;
UILongPressGestureRecognizer *longPressRecognizer;
if (!recognizers)
{
recognizers = [[NSMutableArray alloc] init];
doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleDoubleTapRecognizer:)];
doubleTapRecognizer.numberOfTapsRequired = 2;
longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPressRecognizer:)];
[recognizers addObject:doubleTapRecognizer];
[recognizers addObject:longPressRecognizer];
}
// Don't do anything because already processed.
[cell removeGestureRecognizer:doubleTapRecognizer];
[cell removeGestureRecognizer:longPressRecognizer];
[cell registerGestures:recognizers];
}
-(void)handleDoubleTapRecognizer:(UITapGestureRecognizer*)recognizer
{
NSLog(#"Double Tapped on ImageViewerViewController's main image, so opening editor");
IGCellPath *pathForCurrentCell = [self pathForCurrentCell];
iRpImageAndMedia *imageAndMediaItem = [thePropertyImageSet objectAtIndex:pathForCurrentCell.columnIndex];
imageEditorVC = [[iRpImageEditorViewController alloc] initWithImageAndMediaItem:imageAndMediaItem];
imageEditorVC.navigationItem.title = #"Photo Details Editor";
imageEditorVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(imageEditorDone)];
imageEditorVC.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController pushViewController:imageEditorVC animated:YES];
}
-(void)imageEditorDone
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
-(void)imageEditorCancelled
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
...
This class below is the one that keeps being added to the navigation controller, but never appears.
...
#implementation iRpImageEditorViewController
{
__weak IBOutlet UISwitch *primarySwitch;
__weak IBOutlet UISwitch *postToWebSwitch;
__weak IBOutlet UITextView *descriptionView;
__weak IBOutlet UIImageView *imageView;
__weak IBOutlet UITextField *mediaDate;
__weak IBOutlet UITextField *orderNbr;
__weak IBOutlet UITextField *updatedBy;
__weak IBOutlet UITextField *updateDate;
iRpImageAndMedia *theImageAndMediaItem;
}
-(id)initWithImageAndMediaItem:(iRpImageAndMedia*)imageAndMediaItem
{
if (self = [super initWithNibName:#"iRpImageEditorViewController" bundle:nil])
{
theImageAndMediaItem = imageAndMediaItem;
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self populateUserInterface];
}
-(void)populateUserInterface
{
imageView.image = [theImageAndMediaItem pictureForViewOfSize:imageView.bounds.size];
primarySwitch.on = [theImageAndMediaItem isPrimary];
postToWebSwitch.on = [[theImageAndMediaItem.mediaManagedObj valueForKey:#"postToWeb"] boolValue];
descriptionView.text = [theImageAndMediaItem.mediaManagedObj valueForKey:#"desc"];
updatedBy.text = [theImageAndMediaItem.mediaManagedObj valueForKey:#"updatedBy"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"MM/dd/yyyy"];
[dateFormat setTimeZone:[NSTimeZone localTimeZone]];
NSString *theFormattedDate = [dateFormat stringFromDate:[theImageAndMediaItem.mediaManagedObj valueForKey:#"updateDate"]];
updateDate.text = theFormattedDate;
orderNbr.text = [[theImageAndMediaItem.mediaManagedObj valueForKey:#"order"] stringValue];
}
-(IBAction)postToWebValueChanged:(id)sender
{
UISwitch *theSwitch = sender;
[theImageAndMediaItem.mediaManagedObj setValue:[NSNumber numberWithBool:theSwitch.on] forKey:#"postToWeb"];
}
-(IBAction)primaryValueChanged:(id)sender
{
UISwitch *theSwitch = sender;
[theImageAndMediaItem.mediaManagedObj setValue:[NSNumber numberWithBool:theSwitch.on] forKey:#"primary"];
}
...
-(void)handleDoubleTapRecognizer:(UITapGestureRecognizer*)recognizer
{
NSLog(#"Double Tapped on ImageViewerViewController's main image, so opening editor");
IGCellPath *pathForCurrentCell = [self pathForCurrentCell];
iRpImageAndMedia *imageAndMediaItem = [thePropertyImageSet objectAtIndex:pathForCurrentCell.columnIndex];
imageEditorVC = [[iRpImageEditorViewController alloc] initWithImageAndMediaItem:imageAndMediaItem];
imageEditorVC.navigationItem.title = #"Photo Details Editor";
imageEditorVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(imageEditorDone)];
imageEditorVC.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController pushViewController:imageEditorVC animated:YES];
}
I used below code
- (void)viewDidLoad
{
EKEventStore * store = [[EKEventStore alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dateSelected:) name:#"D" object:nil];
KalViewController *kal = [[KalViewController alloc] init];
kal.delegate = self;
kal.title= [NSString stringWithFormat:#"%#",kal.selectedDate];
[kal loadView];
EventKitDataSource * dataSource = [[EventKitDataSource alloc]init];
kal.dataSource = dataSource;
navController = [[UINavigationController alloc] initWithRootViewController:kal];
[self.customView addSubview:kal.view];
// when I add kal.view inside of my custom view then It displays the list of events and when I click on any row then It does not get pushed to next view screen
}
You have to make change two changes in KalView.m file..
First:In that class,there is an initwithFrame method in which you will get this below code.In that you can change color as per your requirement..
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, frame.size.width, kHeaderHeight)] autorelease];
headerView.backgroundColor = [UIColor orangeColor];
[self addSubviewsToHeaderView:headerView];
[self addSubview:headerView];
Second :In the same class ,there is a one more method i.e addSubviewsToHeaderView:
In that method you will get this code
//Header background gradient
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Kal.bundle/kal_grid_background.png"]];
CGRect imageFrame = headerView.frame;
imageFrame.origin = CGPointZero;
backgroundView.frame = imageFrame;
[headerView addSubview:backgroundView];
[backgroundView release];
Comment this whole code because this is setting image in HeaderView..
I was trying to add the navigation bar to the application programmatically but I didn't got any success.
I had tried the code mentioned below
UIBarButtonItem *alefttbarButton = [[UIBarButtonItem alloc] initWithTitle:#"Setting" style:UIBarButtonItemStyleBordered target:self action:#selector(settingAction:)];
alefttbarButton.style = UIBarButtonItemStyleBordered;
alefttbarButton.tintColor= [UIColor redColor];
self.navigationItem.leftBarButtonItem=alefttbarButton;
self.navigationController.delegate=self;
self.title =#"test";
Here's how I did it. In this particular case I created my views all by hand. Starting in the applicationDidFinishLaunching, I have the following code:
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
mainCtl = [[MainController alloc] init];
[window addSubview:mainCtl.nav.view];
[window makeKeyAndVisible];
As you can see I here allocate and initialize an instance of MainController, which is a subclass of UIViewController.
Then, in the initialization of this MainController I have a call to the navigation bar initialization code:
[self initNavBar];
which is the following function:
- (void) initNavBar
{
printf("initNavBar entered\n");
self.nav = [[UINavigationController alloc] initWithRootViewController: self];
//setup the middle view
int btnCount = 4;
CGRect buttonsFrame = CGRectMake(0, 0, btnCount*BUTTONWIDTH + (btnCount-1)*BUTTONSPACING + 2*BUTTONMARGIN, BUTTONHEIGHT + 2*BUTTONMARGIN);
UIView *buttonsView = [[UIView alloc] initWithFrame:buttonsFrame];
UIButton *button;
CGFloat left = BUTTONMARGIN;
// create button for photo selector invocation
button = [self buttonWithName:#"photo" target:self selector:#selector(showImagePicker) left:left];
//button = [self createButton:#"photo" action:#selector(showImagePicker) left:left];
[buttonsView addSubview:button];
left += (BUTTONWIDTH+BUTTONSPACING);
button = [self buttonWithName:#"crop" target:self selector:#selector(cropImage) left:left];
[buttonsView addSubview: button];
left += (BUTTONWIDTH+BUTTONSPACING);
kissButton = [self buttonWithName:#"kiss" target:self selector:#selector(cropImage) left:left];
[buttonsView addSubview: kissButton];
//left += (BUTTONWIDTH+BUTTONSPACING);
left += (BUTTONWIDTH+BUTTONSPACING);
button = [self buttonWithName:#"mail" target:self selector:#selector(showMailDialog) left:left];
//button = [self createButton:#"mail" action:#selector(showMailDialog) left:left];
[buttonsView addSubview:button];
Class mailClass = (NSClassFromString(#"MFMailComposeViewController"));
//only enable the mail button if the class exists
button.enabled = (mailClass != nil);
printf("initNavBar done\n");
}
This is all working code. If you can look through the cruft you'll manage to get the picture.
Hope this helps.
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];
I need to add a UIView to the main window, the UIView consists in a view with some buttons.
The problem is, the buttons i put inside that view, is not responding for the touch events,
like it have some view in front of it.
That view need to be a singleton class, cause i need to respond the touchevent in any class.
Heres the code for the UIView :
+ (MenuBarView *)sharedMenuBar
{
static MenuBarView *sharedSingleton;
#synchronized(self) {
if (!sharedSingleton) sharedSingleton = [[MenuBarView alloc] init];
return sharedSingleton;
}
}
-(id)init
{
self = [super init];
if(self)
{
self.userInteractionEnabled = YES;
backgroundBarImage = [UIImage imageNamed:#"Barra.png"];
UIImageView * backgroundBar = [[UIImageView alloc]initWithImage:backgroundBarImage];
backgroundBar.contentMode = UIViewContentModeCenter;
backgroundBar.backgroundColor = [UIColor clearColor];
[backgroundBar setFrame:CGRectMake(0, 0, backgroundBarImage.size.width, backgroundBarImage.size.height)];
[self addSubview:backgroundBar];
UIButton * rootBTN = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[rootBTN setFrame:CGRectMake(0, 8, 100, 40)];
[rootBTN addTarget:self action:#selector(selectedBarButton:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:rootBTN];
UIImage * localizacaoIMG = [UIImage imageNamed:#"Localizador"];
UIImageView * localizacaoView = [[UIImageView alloc]initWithImage:localizacaoIMG];
localizacaoView.contentMode = UIViewContentModeScaleAspectFill;
[localizacaoView setFrame:CGRectMake(backgroundBar.frame.origin.x+130, 8, localizacaoIMG.size.width, localizacaoIMG.size.height)];
[backgroundBar addSubview:localizacaoView];
UIButton * localizacaoBTN = [UIButton buttonWithType:UIButtonTypeCustom];
[localizacaoBTN setFrame:CGRectMake(backgroundBar.frame.origin.x+110, 8, 60, 40)];
localizacaoBTN.tag = 1;
[self addSubview:localizacaoBTN];
}
return self;
}
//The event handling method
-(void)selectedBarButton:(UIButton *)sender
{
NSLog(#"OK");
[self.delegate selectedMenuBar:sender.tag];
}
and heres the implementation on the AppDelegate :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[InitialViewController alloc] init];
self.navController = [[EzMallNavViewController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
if(IS_IPOD)
{
[[MenuBarView sharedMenuBar]setFrame:CGRectMake(0, self.window.frame.size.height-51, [MenuBarView sharedMenuBar].frame.size.width, [MenuBarView sharedMenuBar].frame.size.height)];
}
else
{
[[MenuBarView sharedMenuBar]setFrame:CGRectMake(0, self.window.frame.size.height, [MenuBarView sharedMenuBar].frame.size.width, [MenuBarView sharedMenuBar].frame.size.height)];
}
[MenuBarView sharedMenuBar].delegate = self;
[self.window addSubview:[MenuBarView sharedMenuBar]];
return YES;
}
#pragma mark MenuBarDelegateMethods
-(void)selectedMenuBar:(int) tag
{
NSLog(#"Here");
}
It looks like your menu view has a zero size frame so no touches are detected. The buttons appear on screen because the menu view isn't set to clip drawing to its bounds.
Try to set different color for different views and analyze the view hierarchy ,it might be possible that you have added the view in wrong order .