scroll view isn't scrolling when compiled - ios

I have the following app that I've implemented a scroll view (image outlines hierarchy on storyboard:e
I have turned off Auto Layout, as severe posts here seem to indicate this creates a problem.
here is my .h file:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <AssetsLibrary/ALAsset.h>
#import <AssetsLibrary/ALAssetRepresentation.h>
#import <ImageIO/CGImageSource.h>
#import <ImageIO/CGImageProperties.h>
#import <CoreLocation/CoreLocation.h>
#interface DobInAHoonViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate, MFMailComposeViewControllerDelegate, UITextFieldDelegate, CLLocationManagerDelegate>
{
IBOutlet UIPickerView *vehiclePickerView;
UIImagePickerController *picker1;
UIImagePickerController *picker2;
UIImage *image;
IBOutlet UIImageView *imageView;
CLLocationManager *locationManager;
CGFloat animatedDistance;
}
#property (strong, nonatomic) IBOutlet UIImageView *BackgroundImage;
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#property (strong, nonatomic) NSString *Latitude;
#property (strong, nonatomic) NSString *longditute;
#property (strong, nonatomic) NSArray *toRecipients;
#property (strong, nonatomic) ALAssetsLibrary *assetsLibrary;
#property (strong, nonatomic) NSMutableArray *groups;
#property (nonatomic, retain) IBOutlet UITextField *vehilceMake;
#property (nonatomic, retain) IBOutlet UITextField *vehilceColour;
#property (nonatomic, retain) IBOutlet UITextField *regoNumber;
#property (nonatomic, retain) IBOutlet UITextField *location;
#property (nonatomic, retain) IBOutlet UITextField *additionalInfo;
#property (nonatomic, retain) IBOutlet UITextField *vehicleType;
- (IBAction)takePhoto;
-(IBAction)chooseExisting;
-(IBAction)actionEmailComposer;
-(IBAction)textFileReturn:(id)sender;
-(IBAction)DismissKeyboard:(id)sender;
#end
and my .m file:
#import "DobInAHoonViewController.h"
#interface DobInAHoonViewController ()
#end
#implementation DobInAHoonViewController
#synthesize BackgroundImage;
#synthesize vehilceColour;
#synthesize vehilceMake;
#synthesize regoNumber;
#synthesize Latitude;
#synthesize location;
#synthesize longditute;
#synthesize additionalInfo;
#synthesize toRecipients;
#synthesize assetsLibrary;
#synthesize groups;
#synthesize vehicleType;
#synthesize scrollView;
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLLFRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 140;
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[vehilceMake resignFirstResponder];
[vehilceMake resignFirstResponder];
[vehilceColour resignFirstResponder];
[location resignFirstResponder];
[additionalInfo resignFirstResponder];
[regoNumber resignFirstResponder];
return YES;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:(CGSizeMake(320, 1000))];
locationManager = [[CLLocationManager alloc]init];
toRecipients = [[NSArray alloc]initWithObjects:#"scott.boon#shellharbour.nsw.gov.au", nil];
BackgroundImage.alpha = 0.3;
static int emergAlertCounter;
if (emergAlertCounter <1) {
UIAlertView *emergencyAlert = [[UIAlertView alloc]
initWithTitle:#"NOTE" message:#"Do not endanger your life to dob in a hoon. If your life is threatened, or you are reporting an emergency situation, exit this app and dial '000' IMMEDIATLY!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[emergencyAlert show];
emergAlertCounter = emergAlertCounter+1;
}
}
for some reason, when i run the app, the scroll view is not scrolling. I have set the property to scroll in the interface builder.
Any suggestions would be greatly appreciated.

You'll have to make sure your scroll view is smaller than 320 x 1000 and that the embedded view is larger than 320 x 1000

Related

objective C making UITextField for vc1 become UILabel vc2

I am trying to get my UITextField email in my first view controller to become the UILabel in my next view controller. It says there is an error stating there is no visible #interface for NSString declares the selector initvalue. I thought the interface was being loaded from the vc1.h file when you imported it on the vc2? any help would be nice. Heres what I have so far:
vc1.h
#import <UIKit/UIKit.h>
#interface loginUserViewController : UIViewController
#property (nonatomic, retain, strong) IBOutlet UITextField *email;
#property (nonatomic, retain) IBOutlet UITextField *password;
#property (nonatomic, retain) IBOutlet UIButton *login;
#property (nonatomic,retain) IBOutlet UIButton *registerBtn;
-(IBAction)loginUser:(id)sender;
#end
vc2.h
#import <UIKit/UIKit.h>
#import "loginUserViewController.h"
#interface Home : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *username;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *Nav;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *logout;
-(IBAction)logout:(id)sender;
-(IBAction)bandHome:(id)sender;
#end
vc2.m
import "Home.h"
#import "loginUserViewController.h"
#interface Home ()
#end
#implementation Home
#synthesize username, band1, band2, band3;
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self){
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
loginUserViewController *object = [[loginUserViewController alloc]init];
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text initValue]];
username.text = string;
}
vc1.m
#import "loginUserViewController.h"
#import "Home.h"
#import "createBandViewController.h"
#interface loginUserViewController ()
#end
#implementation loginUserViewController
#synthesize email, password;
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)viewDidload
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setEmail:nil];
[self setPassword:nil];
[super viewDidUnload];
}
-(IBAction)loginUser:(id)sender {
if ([email.text isEqualToString:#""] || [password.text isEqualToString:#""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"alert" message:#"Please Fill all the field" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
Simply replace this string:
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text initValue]];
with this string:
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text intValue]];
and if you want simply the email just as a string then replace it with this string
NSString *string = [[NSString alloc] initWithFormat:#"%#",object.email.text];
your error will be resolved.Hope it helps :)
First of All in VC2.h
#import <UIKit/UIKit.h>
#import "loginUserViewController.h"
#interface Home : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *username; // Keep property strong to get the value
in VC2.m
#synthesize username;
Now in VC1.h
#import <UIKit/UIKit.h>
#import "homeviewcontroller.h"
#interface loginUserViewController : UIViewController
#property (nonatomic, strong) IBOutlet UITextField *email;
#property (nonatomic, strong) IBOutlet UITextField *password;
#property (nonatomic) nsstring *username;
-(void)viewDidLoad
{
[super viewDidLoad];
username= self.email.text;
homeviewcontroller *object = [[homeviewcontroller alloc]init];
object.username.text=username;
}

Objective c - pass back string value using delegate

I want to pass UITextField *nameText from GreenViewController to UILabel *nameValue in ViewController using delegate.
I made delegate, the onSave method in ViewController is called but the screen is not going back and the name is not passed.
What is the problem?
Here are the header and impelentation files:
GreenViewController.h
#import <UIKit/UIKit.h>
#protocol GreenViewDelegate <NSObject>
-(void)onSave:(NSString*)nameValue;
#end
#interface GreenViewController : UIViewController
#property id<GreenViewDelegate> delegate;
#property (nonatomic) NSString* sliderValuePassed;
#property (weak, nonatomic) IBOutlet UIButton *Next;
#property (weak, nonatomic) IBOutlet UIButton *Save;
#property (weak, nonatomic) IBOutlet UIButton *Back;
#property (weak, nonatomic) IBOutlet UILabel *sliderTextValue;
#property (weak, nonatomic) IBOutlet UITextField *NameText;
- (IBAction)save:(id)sender;
#end
GreenViewController.m
#import "GreenViewController.h"
#import "ViewController.h"
#interface GreenViewController ()
#end
#implementation GreenViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.sliderTextValue.text = self.sliderValuePassed;
}
- (IBAction)back:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)save:(id)sender {
[self.delegate onSave:self.NameText.text];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#import "GreenViewController.h"
#interface ViewController : UIViewController <GreenViewDelegate>
#property (weak, nonatomic) IBOutlet UISlider *slider;
#property (weak, nonatomic) IBOutlet UILabel *sliderTextValue;
#property (weak, nonatomic) IBOutlet UIButton *EnterName;
#property (weak, nonatomic) IBOutlet UILabel *NameValue;
#property (weak, nonatomic) IBOutlet UIButton *LikeIOS;
#property (weak, nonatomic) IBOutlet UISwitch *CheckboxIOS;
#end
ViewController.m
#import "ViewController.h"
#import "RedViewController.h"
#import "GreenViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.sliderTextValue.text = [NSString stringWithFormat:#"Slider value = %d",(int)self.slider.value];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"yellowToGreen"]){
GreenViewController* gVC = segue.destinationViewController;
gVC.sliderValuePassed = [NSString stringWithFormat:#"Slider value = %d",(int)self.slider.value];
gVC.delegate = self;
}else if([segue.identifier isEqualToString:#"yellowToRed"]){
RedViewController* rVC = segue.destinationViewController;
rVC.sliderValuePassed = [NSString stringWithFormat:#"Slider value = %d",(int)self.slider.value];
rVC.CheckboxIOS = self.CheckboxIOS;
}
}
- (IBAction)sliderChangeValue:(id)sender {
int sliderVal = self.slider.value;
self.sliderTextValue.text = [NSString stringWithFormat:#"Slider value = %d",sliderVal];
}
-(void)onSave:(NSString*)nameValue{
NSLog(#"onSave in father controller");
self.NameValue.text = [NSString stringWithFormat:#"Name = %#",nameValue];
}
#end
I assume you didnt set the delegate .
Set it like this:
GreenViewController *myVc = [[GreenViewController alloc] init];
myVc.delegate = self;
Put this in your view controller view did load method!!!
try with GreenViewController.h:
#property (nonatomic, assign) id<GreenViewDelegate> delegate;
and GreenViewController.m:
- (IBAction)save:(id)sender {
[_delegate onSave:self.NameText.text];
[self.navigationController popViewControllerAnimated:YES];
}
ViewController.* seems to be OK

Keyboard not resigning when i tap the return key (xcode)

I am trying to get the keyboard to go away, when I press the return key on my application heres my code from the .m:
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
and the code in the .h:
- (BOOL)textFieldShouldReturn:(UITextField* )textField;
But when I run the application and hit the return key nothing happens. What am I doing wrong?
my .h:
#import <UIKit/UIKit.h>
#interface ChemicalInfoViewController: UIViewController{
IBOutlet UIScrollView *ChemicalInforScroller;
}
#property (strong, nonatomic) IBOutlet UITextField *PPMForChlTextField;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForChlTextField;
#property (strong, nonatomic) IBOutlet UITextField *PPMForAlkTextField;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForAlkTextField;
#property (strong, nonatomic) IBOutlet UITextField *PPMForPHTextField;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForPHTextField;
- (IBAction)SumbitCDI:(UIButton *)sender;
#property (strong, nonatomic) IBOutlet UILabel *PPMLabelForChl;
#property (strong, nonatomic) IBOutlet UILabel *GallonsLabelForChl;
#property (strong, nonatomic) IBOutlet UILabel *PPMLabelForAlk;
#property (strong, nonatomic) IBOutlet UILabel *GallonsLabelForAlk;
#property (strong, nonatomic) IBOutlet UILabel *PPMLabelForPH;
#property (strong, nonatomic) IBOutlet UILabel *GallonsLabelForPH;
#property (strong, nonatomic) IBOutlet UITextField *ChlorinePoundsTextField;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForAlkDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *PhPoundsTextField;
#property (strong, nonatomic) IBOutlet UITextField *AlkPoundsTextField;
#property (strong, nonatomic) IBOutlet UITextField *LbsForAlkDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *PPMForAlkDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *LbsForPhDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *PPMForPhDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForPhDecreaser;
- (IBAction) clickedBackground;
#interface ChemicalInfoViewController : UIView <UITextField>
#end
and my .m:
#import "ChemicalInfoViewController.h"
#interface ChemicalInfoViewController ()
#end
#implementation ChemicalInfoViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[ChemicalInforScroller setScrollEnabled:YES];
[ChemicalInforScroller setContentSize:CGSizeMake(320, 1000)];
self.textField.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction) clickedBackground {
[self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
In your .h, remove:
- (BOOL)textFieldShouldReturn:(UITextField* )textField;
And it will work as it should, given that in your .h, you conform to the protocol:
#interface yourViewController : UIView <UITextFieldDelegate>
And set up the delegate like so:
yourTextField.delegate = self;
Edit regarding to the #end:
In your .m, add a #end to the bottom; so , it becomes (scroll to the very bottom):
#implementation ChemicalInfoViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[ChemicalInforScroller setScrollEnabled:YES];
[ChemicalInforScroller setContentSize:CGSizeMake(320, 1000)];
self.textField.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction) clickedBackground {
[self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
#end //Here :-)
You didn't set the delegates for your textfields.
In "viewDidLoad" add
_ChlorinePoundsTextField.delegate = self;
_GallonsForAlkDecreaser.delegate = self;
_PhPoundsTextField.delegate = self;
_AlkPoundsTextField.delegate = self;
_LbsForAlkDecreaser.delegate = self;
_PPMForAlkDecreaser.delegate = self;
_LbsForPhDecreaser.delegate = self;
_PPMForPhDecreaser.delegate = self;
_GallonsForPhDecreaser.delegate = self;
none of these methods seemed to be working for some reason but what i did end up doing was creating a DidEndOnExit action and resigned the keyboard under that action for each textfield

Creating image frame not displaying in simulator

I have an app that captures the users signature, myviewcontroller displays the signature capture. I'm attempting to create a rectangle in the center of the screen that is centered for this to happen using CGRect. When I run this I get no errors, but I get the picture below and I can't figure out what is causing this.
Within the CGRect code, I am trying to have the rectangle that is created be centered in the middle of the screen, and the target device is ipad. I've posted both the .h and .m files, the .m file is incomplete as the rest has to do with the code used to capture the signature then save it.
Any help would be appreciated.
//MyViewController.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import <Foundation/Foundation.h>
#interface MyViewController : UIViewController <UIAlertViewDelegate>
#property (nonatomic, strong) UIImageView *mySignatureImage;
#property (nonatomic, assign) CGPoint lastContactPoint1, lastContactPoint2, currentPoint;
#property (nonatomic, assign) CGRect imageFrame;
#property (nonatomic, assign) BOOL fingerMoved;
#property (nonatomic, assign) float navbarHeight;
#property (nonatomic, assign) UIImageView* imageView;
#property (nonatomic, retain) NSData*image;
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
//Save and cancel buttons
- (IBAction)cancel:(id)sender;
- (IBAction)save:(id)sender;
#end
//MyViewController.m
#import "MyViewController.h"
#interface MyViewController ()
#end
#implementation MyViewController
#synthesize mySignatureImage;
#synthesize lastContactPoint1, lastContactPoint2, currentPoint;
#synthesize imageFrame;
#synthesize fingerMoved;
#synthesize navbarHeight;
#synthesize image;
#synthesize imageView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
CGRect imageFrame = CGRectMake(
CGRectGetMidX(self.view.frame) - CGRectGetMidX(imageView.frame),
CGRectGetMidY(self.view.frame) - CGRectGetMidY(imageView.frame),
CGRectGetWidth(imageView.frame),
CGRectGetHeight(imageView.frame));
// //allocate an image view and add to the main view
mySignatureImage = [[UIImageView alloc] initWithImage:nil];
mySignatureImage.frame = imageFrame;
mySignatureImage.backgroundColor = [UIColor whiteColor];
[self.view addSubview:mySignatureImage];
}
Move the code (except for [super viewDidLoad]) in viewDidLoad to a later stage, such as viewWillAppear. During viewDidLoad the layout of the views is not yet complete so their bounds/frames are not yet set to their final values.
Try to replace this line:
mySignatureImage = [[UIImageView alloc] initWithImage:nil];
with:
mySignatureImage = [[UIImageView alloc] init];

Xcode saying that the variable "beacon" is undeclared?

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated]
[[self.locationManager startRangingBeaconsInRegion: self.rangedRegion]
]}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidAppear:animated]
[[self.locationManager stopRangingBeaconsInRegion: self.rangedRegion]
]}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tagname.text = [self.TagDetail objectForKey:#"Name"];
self.title = [self.TagDetail objectForKey:#"Name"];
NSString *proximity = #"near";
if ([beacon.proximity == CLProximityNear:]) {
NSLog(#"Show near");
[self.near setHidden:(NO)];
[self.far setHidden:(YES)];
[self.immediate setHidden:(YES)];
}
else if ([beacon.proximity == CLProximityFar]) {
NSLog(#"Show");
[self.near setHidden:(YES)];
[self.far setHidden:(NO)];
[self.immediate setHidden:(YES)];
}
else if ([beacon.proximity == CLProximityImmediate]) {
NSLog(#"Show");
[self.near setHidden: (YES)];
[self.far setHidden: (YES)];
[self.immediate setHidden: (NO)];
}
Heres the .h file
#interface TagDetailViewController : UIViewController
#property (nonatomic, strong) PFObject* TagDetail;
#property (strong, nonatomic)IBOutlet UILabel *tagname;
#property (nonatomic, strong)IBOutlet UIImageView *immediate;
#property (nonatomic, strong)IBOutlet UIImageView *near;
#property (nonatomic, strong)IBOutlet UIImageView *far;
#property (nonatomic, strong)IBOutlet UIButton *showOnMap;
#property CLLocationManager *locationManager;
#property CLBeaconRegion *rangedRegion;
#property NSUUID *artemisUUID;
#property CLBeaconMajorValue *major;
#property CLBeaconMinorValue *minor;
#property CLBeacon *proximity;
#end
Its telling me that the variable beacon is not identified, but doing so in the header file as *beacon doesn't remove any errors. What am I doing wrong? Im really new to this language so that is a large part of why Im running into errors, but I cant figure this one out.
You don't have a variable named beacon, you have a CLBeacon object named proximity.

Resources