Switch View issue - objective-c

OK i asked this yesturday but i updated it with more detail as to the problems im having. The problem im having is this. When i run my app, the main view looks fine, just as it is suppose to. But, when i click a button to go to the next view, that view is shifted up about 20pixels. When i goback to the main screen it is shifted up the same.
The only time that my app looks like it is suppose to is when i first load it, once i click a button and start changing views, every view after i leave the mainview that first time is shifted up 20 pixels, even the mainview when i go back to it. I started having this issue when i upgraded from xcode 3.2 to xcode 4.0 beta. There is one way i have found to switchviews that doesnt make the views shift up BUT, i have an issue with this way. I have users input data on view1, on button click it switches to view2 and sends that data from 1 to 2. Using the switchview method that shows my views as they are suppose to be my data dont want to transfer to view2. Using the switchview method that gives me the data transfer from 1 to 2 that i need, it shifts the views up by 20 pixels. below are the examples of what im using.
-- with xcode 4 this way causes my views to shift up 20 pixels where as xcode 3.25 it worked great, had no issues and it transfered the data from view1 to view2.
- (IBAction)calculate:(id)sender {
MaleResultsController *maleResults = [[MaleResultsController alloc] initWithNibName:#"MaleResultsController" bundle:nil];
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view cache:YES];
[self.view addSubview:maleResults.view];
maleResults.displayAge.text = ageInput.text;
maleResults.displayHeight.text = heightInput.text;
maleResults.displayWeight.text = weightInput.text;
NSString *minWeightString = [[NSString alloc] initWithFormat:#"%.0f", [self getMinWeight]];
maleResults.displayMinWeight.text = minWeightString;
[minWeightString release];
NSString *maxWeightString = [[NSString alloc] initWithFormat:#"%.0f", [self getMaxWeight]];
maleResults.displayMaxWeight.text = maxWeightString;
[maxWeightString release];
NSString *maxBodyFatString = [[NSString alloc] initWithFormat:#"%.0f", [self getMaxBodyFatPercentage]];
maleResults.displayMaxBodyFatPercentage.text = maxBodyFatString;
[maxBodyFatString release];
NSString *bodyFatString = [[NSString alloc] initWithFormat:#"%.0f", [self getBodyFatPercentage]];
maleResults.displayBodyFat.text = bodyFatString;
[bodyFatString release];
NSString *abdomenAvgString = [[NSString alloc] initWithFormat:#"%.2f", [self getAbdomenAvg]];
maleResults.abdomenAvg.text = abdomenAvgString;
[abdomenAvgString release];
NSString *neckAvgString = [[NSString alloc] initWithFormat:#"%.2f", [self getNeckAvg]];
maleResults.neckAvg.text = neckAvgString;
[neckAvgString release];
NSString *abNeckFactorString = [[NSString alloc] initWithFormat:#"%.2f", [self getAbNeckFactor]];
maleResults.abdomenNeckFactor.text = abNeckFactorString;
[abNeckFactorString release];
//
// [self.navigationController pushViewController:maleResults animated:YES];
[UIView commitAnimations];
}
-- with xcode 4 this method works to switch views correctly but doesnt transfer textfield input on view1 to label output on view2..
- (IBAction)calculate:(id)sender {
MaleBFCResults *maleBFCresults = [[MaleBFCResults alloc] initWithNibName:#"MaleBFCResults" bundle:nil];
MaleBFCdata *maleBFCData = [[MaleBFCdata alloc] init];
maleBFCresults.maleData = maleBFCData;
maleBFCresults.displayAge = ageInput.text;
maleBFCresults.displayHeight = heightInput.text;
maleBFCresults.displayWeight = weightInput.text;
maleBFCresults.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:maleBFCresults animated:YES];
[maleBFCresults release];
}
I have been searching for ways to fix this issue for a couple weeks now, and havnt been able to find anything to help. I havnt put all my forumlas and calculations into place yet on this new one because i want to make sure that the UI is functioning properly before i spend the time writing out all the code for the calculations. I like the transitions that "modalTransitionStyle" gives me over the "setAnimationTransition". Which is good because it works properly to switch views i just cant get it to transfer data from view1 to view2.
Im sure if i had to i could always revert back to the previous version of xcode but im trying not to have to do have to do that, if anyone has had a similar issue and has a solution i would really appreciate it. there may even be a different way to send data from view1 to view2 that would work that i havnt tried yet, but i havnt found a good way to do that either.
thanks in advance for any help with this issue..

I also faced the same problem of shifting view adn resolved it as below. The following code snippet switches from viewController to msgViewController.
Open the mainWindow.xib and add the UIViewController Object from the Library. Change its class to your Class that handles the specified viewController and then comes the click. Go to the properties section of the Attribute Inspector and set the respective Nib Name for the Controller and now save and exit the IB.
And the code changes to
-(void) flipToBack
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}
Hope this helps you!!
If it does please communicate.

Adjust the frame of those views regarding to the status bar.
However, I wouldn't rely on the application delegate object to handle multiple views. Have a root view controller which takes care of those views.

Related

Which one of the two NSTextViews has been edited? doCommandBySelector is always returns the first one

I'm desperate to find the answer, so I opened TextLayoutDemo sample project from Apple. The point is that: I have two NSTextViews for column view. Everything works fine, text I enter is successfully laying out in those two text views via single layout manager:
NSLayoutManager *twoColumnLayoutManager = [[NSLayoutManager alloc] init];
NSTextContainer *firstColumnTextContainer = [[NSTextContainer alloc] init];
NSTextContainer *secondColumnTextContainer = [[NSTextContainer alloc] init];
NSTextView *firstColumnTextView = [[NSTextView alloc] initWithFrame:NSMakeRect(0, 0, 240, 360) textContainer:firstColumnTextContainer];
firstColumnTextView.delegate = self;
NSTextView *secondColumnTextView = [[NSTextView alloc] initWithFrame:NSMakeRect(240, 0, 240, 360) textContainer:secondColumnTextContainer];
secondColumnTextView.delegate = self;
[firstColumnTextContainer setContainerSize:NSMakeSize(240, 360)];
[secondColumnTextContainer setContainerSize:NSMakeSize(240, 360)];
[twoColumnLayoutManager addTextContainer:firstColumnTextContainer];
[twoColumnLayoutManager addTextContainer:secondColumnTextContainer];
[twoColumnLayoutManager replaceTextStorage:[firstTextView textStorage]];
[[secondWindow contentView] addSubview:firstColumnTextView];
[[secondWindow contentView] addSubview:secondColumnTextView];
But my goal is to get to know in which one text views the user edits a text. If it's the left one, I need to call one method, but if it's the right one, I want to call another method. And it seems impossible to recognize the correct text view, because delegate always get notified by the first text view.
- (BOOL) textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector {
NSLog(#"edit: %#", textView);
return NO;
}
This method is always prints the first text view, even if I change text in the second one. And I see it's going according to docs, where Apple says there always will be just the first NSTextView in series.
But how can I solve my problem then?
Just tell me, if this solution is the one I am looking for. Because, in fact, it works just fine. The one thing I don't understand is why Cocoa text system is so tricky where it is not necessary?
- (void)textStorageDidProcessEditing:(NSNotification *)aNotification {
// that's the active text view
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
NSTextView *activeTextView = (NSTextView *)[keyWindow firstResponder];
NSLog(#"%p", activeTextView);
}
UPDATE: this works only if user clicked the mouse button. Arrow keys do not update window's first responder:(

Prevent shutter animation from appearing full screen when using cameraOverlayView [duplicate]

I have a transparent view with a rectangle drawn onto it using CoreGraphics.
When the camera launches the custom overlay view is above the shutter animation.
What you see is the standard camera shutter with the custom rectangle above it.
How do I get it to go in the right place, underneath the shutter animation? I've looked at other sample code but it's for OS 3.1 and doesn't seem to do anything differently.
Here's my code:
-(IBAction)cameraButton{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerCameraDeviceRear]){
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Add the OverlayView with the custom Rectangle
CGRect overlayFrame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
OverlayView *overlayView = [[OverlayView alloc]initWithFrame:overlayFrame];
picker.cameraOverlayView = overlayView;
[overlayView release];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
On the iPad this problem doesn't exist, and the overlay view is behind the shutter animation by default. But on the iPhone, the overlay appears at front.
I've found a solution that worked for me.
You have to set your overlay view as a subview in this method:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (!viewController)
return;
UIView* controllerViewHolder = viewController.view;
UIView* controllerCameraView = [[controllerViewHolder subviews] objectAtIndex:0];
UIView* controllerPreview = [[controllerCameraView subviews] objectAtIndex:0];
[controllerCameraView insertSubview:self.overlayView aboveSubview:controllerPreview];
}
Hope it helps
Original source:
http://www.alexcurylo.com/blog/2009/06/18/uiimagepickercontroller-in-3-0/
You may not do anything else other than what you're already doing; if iOS decides to put your overlay view over the shutter, you'll just have to live with it (unless you want to risk getting rejected from the app store).
As an imperfect workaround, you could start your overlay with alpha=0 and then set alpha to 1 a second or two later. But there is no set time period that the shutter appears for before 'opening' (I think it depends on how long it takes to initialize the camera hardware), so sometimes your interface might not appear until late and sometimes might appear too early.
As of 4.3.3, the shutter animation is broken because elements are displayed on top, and then snap underneath when the animation starts. I've filed this as a Radar: http://openradar.appspot.com/radar?id=1204401
I answered a similar question here. What worked for me (in iOS 6) was setting the cameraOverlayView in navigationController:willShowViewController:animated.
- (void) navigationController:(UINavigationController*) navigationController willShowViewController:(UIViewController*) viewController animated:(BOOL) animated {
self.imagePickerController.cameraOverlayView = ...; // your camera overlay view
}

iOS app crashed while loading ad?

Here is my code in viewDidLoad method:
self.bannerView_= [[GADBannerView alloc] initWithFrame:CGRectMake(80,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
self.bannerView_.adUnitID = #"a15037256bd8776";
self.bannerView_.rootViewController =self;
[self.view addSubview:self.bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
My app is designed for landscap mode only. And it works fine in home screen, but when i goes to other screens and trying to load ad(by clicking on banner) the ad is loaded in half part of screen, other half part of screen remains unchanged.
Can anybody help me please.
try following code
self.adBanner= [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
self.adBanner.adUnitID = #"a15037256bd8776";
self.adBanner.delegate = self;
self.adBanner.rootViewController =self;
[self.view addSubview:self.adBanner];
[self.adBanner loadRequest:[self createRequest]];
After more then two days finally i resolved the issue-
Instead to instantiate and call GADBannerView from viewDidLoad of all my view's, I've created a singleton class and use it. see this link for more help

My UITabBar doesn't show up

Okay guys, maybe you can help me out with this one. I'm about ready to pull my hair out.
Recently I decided to upgrade my app and make it look better, and with that I wanted to move it into full support for iPad platforms as well. For a while everything worked great. Just press copy MainWindow.xib for iPad, add the views that I used on the iPhone configurations, and everything should be great, but that didn't work too well. Take a look:
Here is the iPhone screenshot:
Here is the iPad screenshot:
Where's the tab bar? I don't understand! I added the initial view when I was first putting it together, but when I linked all of the IBOutlets to the proper pieces, the tab bar no longer shows up.
Screenshot of IB:
Tab Bar properties:
Tint: A bluish color
Image Tint: A goldish color
Mode: Scale to fill
Tag: 0
User Interaction Enabled: (Checked)
Multiple Touch: (Unchecked)
Alpha: 1
Opaque: (Checked)
Hidden (Unchecked)
Clears Graphic Context: (Checked)
Clip Subviews: (Unchecked)
Autoresize Subviews: (Checked)
Stretching: (x,y,w,h):(0,0,1,1)
The viewController.h file is a delegate for UITabBar, UITextField, and UITextView
ViewDidLoad (bar is the IBOutlet for the tab bar):
- (void)viewDidLoad
{
[super viewDidLoad];
[self playMovieIntro];
NSURL *url = [NSURL URLWithString:#"http://www.faithlifefellowship.us/Audio/Sermons/NewSermonBanner.png"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
if(!image == NULL)
{
NewSermonBanner.image = image;
}
series = [[Series alloc] init];
SeriesName = #"";
NSRange range = [[[UIDevice currentDevice] name] rangeOfString:#"iPad"];
int i = 0;
if(range.location != NSNotFound)
i = 1;
bar.selectedItem = hometab;
//set delegates
[bar setDelegate:self];
[personalName setDelegate:self];
[personalEmail setDelegate:self];
[content setDelegate:self];
[prContent setDelegate:self];
[prName setDelegate:self];
[prEmail setDelegate:self];
}
I'm stumped. If you have any ideas or need any more information, let me know.
Thanks!
I'm going to give you a few things I'm getting in order to fix this. It will be tons easier if you could upload the source code for me/us to download and be able to pinpoint the problem.
Sometimes (I can't remember exactly when) I've had my navigation bar not show up because it was missing a connection.
Make sure you are not hiding the tab bar anywhere in code, though it doesn't seem to be the case since it shows up on iPhone.
Otherwise I'm gonna take a guess and say it's something in the NIB. Here are some things you can try:
Check all your connections to outlets
Make sure your objects in the NIB are of the correct class
Verify that the tab bar's "hidden" property is not check in Interface Builder
Compare and verify all the structure of the NIB file between iPhone and iPad
These are just some ideas :) again if you can post the code it would be fantastic.
Let us know how it goes,
Felipe
I had this problem with a app that support both iPhone and iPad. Make sure 'is initial view controller' is checked for the UITabBarController when you examine the view controller using the object inspector. When you do this, xcode will display a 'inbound' arrow on the left side of the view controller if you're using storyboards.

UIScrollView adding UIViewController as a sub view? with UIPageControl

I am currently working on my application and would like to have a UIScrollView and UIPageControl which would allow the user to swipe the screen left and right to get to different view controllers.
I have this working so far, so that I can swipe left and right to see either view controller however I am finding that when one of my UIViewControllers needs to access it delegate nothing happens, for example UITableViewDelegate.
This is the code i have so far in my scrollViewController
CGRect frame2;
frame2.origin.x = self.scrollView.frame.size.width * 1;
frame2.origin.y =30;
frame2.size = self.scrollView.frame.size;
myViewController *vc3 = [[myViewController alloc] initWithNibName:#"myViewController" bundle:nil];
vc3.view.frame = frame2;
[self.scrollView addSubview:vc3.view];
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * 2, self.scrollView.frame.size.height);
One thing I am not able to do also is release [vc3 release]; after adding it to the scrollView the app will just crash.
Any help would be great, also please let me know if I am going about this the wrong way.
Thanks Aaron
By adding v3.view , v3's retain count wont increase. So you cant release v3. you can
[v3.view release];