iPhone Simulator Text Box Takes up Whole Screen - iphone

Here is my code. Not sure what's awry.
controller.h
#import <UIKit/UIKit.h>
#interface ch4iOSPracticeViewController : UIViewController {
UITextField *nameField;
UITextField *numberField;
}
#property (nonatomic, retain) IBOutlet UITextField *nameField;
#property (nonatomic, retain) IBOutlet UITextField *numberField;
#end
controller.m
#import "ch4iOSPracticeViewController.h"
#implementation ch4iOSPracticeViewController
#synthesize nameField;
#synthesize numberField;
delegate.m Everything properly released.
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}

When you add a textField to the iPhone using interface builder, I am guessing that there was another view already present there; So when you pulled the textField over it, it had stretched. Try pulling it inside a plain View.
It is either that you pulled a textview instead of a textfield.

Related

Programmatically focus on UITextView is not working

Before closing the post as duplicate,believe me,i am searching this for 2 days but still nothing.
I will try to be as clear as possible:
I have a view with a textview.I need to set focus automatically on the textview so the keyboard ill appear.
PostView.h
#interface PostView : UIViewController{
UITextView *txtPesto;
}
#property (nonatomic,retain) IBOutlet UITextView *txtPesto;
#end
PostView.m
#import "PostView.h"
#implementation PostView
#synthesize txtPesto;
- (void)viewDidLoad
{
[super viewDidLoad];
[txtPesto becomeFirstResponder];
}
For some very strange reason my code is not working,although i have tried many samples and different approaches.
Any help?
Answer from my comment (for closing question):
Right click on textView, and "new referncing outlet", maybe that will be helpful?
You are declaring txtPesto twice in your .h file:
#interface PostView : UIViewController{
UITextView *txtPesto;
}
#property (nonatomic,retain) IBOutlet UITextView *txtPesto;
#end
When you declare it as a property, you don't need to do it again. So remove the extra declaration, and just use this:
#interface PostView : UIViewController
#property (nonatomic,retain) IBOutlet UITextView *txtPesto;
#end
I don't see any other reason that becomeFirstResponder wouldn't work.

iPhone connect textfield end on exit event to button press event

I have a text field and a button. When the button is pressed, it calls a routine. I want the textfield end on exit to call the same routine without having to duplicate the code. ViewController.h is below
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityind;
#property (weak, nonatomic) IBOutlet UITextField *search;
- (IBAction)calculate:(id)sender;
#end
In ViewController.h implement UITextFieldDelegate like so:
#interface ViewController : UIViewController <UITextFieldDelegate>
and then use the method
-(BOOL)textFieldShouldReturn:(UITextField *)textField
and call your IBAction and resignFirstResponder, I would also auto-enable return key.
[EDIT1]
In your viewController header:
#interface ViewController : UIViewController <UITextFieldDelegate>
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityind;
#property (weak, nonatomic) IBOutlet UITextField *search;
-(void)doSomeWork;
-(IBAction)calculate:(id)sender;
#end
Simply implement the functionality in a 2nd tier routine.
In your viewController.m file:
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
if(search == textField){
[textField resignFirstResponder];
[self doSomeWork];
}
return YES;
}
-(void)doSomeWork{
// Do whatever you want to do here!!!
}
-(IBAction)calculate:(id)sender{
[self doSomeWork];
}
In your xib file you will have to connect up the button to the "calculate" action, the search to the proper UITextField.
You can set the delegate of the UITextField either graphically in the Interface Builder, or in code. If in code, then within your viewController.m file add the line:
search.delegate = self;
to your viewDidLoad method as follows:
-(void)viewDidLoad{
[super viewDidLoad];
search.delegate = self;
}

Memory leak vs Zombie - iPhone

My iPhone app is either crashing due to to a zombie, or leaking memory.. I've narrowed it down to 3 lines of code and can reliably get one of the two things to happen by commenting/uncommenting the code. The bugs occur when navigation between a list of results (tableView) and a details page containing a map and a few labels, memory leak happens the first time I navigation from the map back to the list of results, the zombie occurs after maybe 5/6 times navigating to different results and back.
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#define METERS_PER_MILE 1609.344
#interface ResDetailsPageVC : UIViewController <MKMapViewDelegate, UIAlertViewDelegate> {
UISegmentedControl *mapTypeSwitcher;
MKMapView *mapView;
UILabel *nameLabel;
UIButton *addressLabel;
UILabel *telephoneLabel;
NSString *address;
}
#property (nonatomic, retain) IBOutlet UISegmentedControl *mapTypeSwitcher;
#property (nonatomic, retain) IBOutlet MKMapView *mapView;
#property (nonatomic, retain) IBOutlet UILabel *nameLabel;
#property (nonatomic, retain) IBOutlet UIButton *addressLabel;
#property (nonatomic, retain) IBOutlet UILabel *telephoneLabel;
- (IBAction)segmentedControlIndexChanged;
- (IBAction)callButtonClick;
- (IBAction)addressClick;
- (void) callNumber;
#end
#synthesize mapView;
#synthesize mapTypeSwitcher;
#synthesize nameLabel, addressLabel, telephoneLabel;
- (void)dealloc {
// if these lines are commented out - memory leak
// if not - zombie?!
/*self.telephoneLabel = nil;
self.addressLabel = nil;
self.nameLabel = nil;*/
self.mapView = nil;
self.mapTypeSwitcher = nil;
[super dealloc];
}
Somewhere some other piece of code is using the same object whose address is stored in one of those three properties, but that other piece of code has not properly retained the object.
I recommend this to you:
- (void)dealloc {
[telephoneLabel release]; telephoneLabel = nil;
[addressLabel release]; addressLabel = nil;
....
[super dealloc];
}

UIViewController does not recognize method

please help me to resolve this issue
i have a view controller in a navigation stack named firstviewcontroller
FirstViewController.h
#class ImperialPickerController;
#class FractionPickerController;
#class MetricPickerController;
#interface FirstViewController : UIViewController {
UIView *pickerViewContainer;
ImperialPickerController *ImperialPickerController;
FractionPickerController *FractionPickerController;
MetricPickerController *MetricPickerController;
UIView *ImperialPickerViewContainer;
UIView *FractionPickerViewContainer;
UIView *MetricPickerViewContainer;
UISegmentedControl *segmentedControl;
NSInteger selectedUnit;
}
#property(nonatomic,retain) IBOutlet UIView *pickerViewContainer;
#property(nonatomic,retain) IBOutlet UIView *ImperialPickerViewContainer;
#property(nonatomic,retain) IBOutlet UIView *FractionPickerViewContainer;
#property(nonatomic,retain) IBOutlet UIView *MetricPickerViewContainer;
#property(nonatomic,retain) IBOutlet ImperialPickerController *ImperialPickerController;
#property(nonatomic,retain) IBOutlet FractionPickerController *FractionPickerController;
#property(nonatomic,retain) IBOutlet MetricPickerController *MetricPickerController;
#property(nonatomic,retain) IBOutlet UISegmentedControl *segmentedControl;
-(IBAction)toggleUnit;
#end
FirstViewController.m
#implementation FirstViewController
#synthesize ImperialPickerController;
#synthesize FractionPickerController;
#synthesize MetricPickerController;
#synthesize ImperialPickerViewContainer;
#synthesize FractionPickerViewContainer;
#synthesize MetricPickerViewContainer;
#synthesize pickerViewContainer;
#synthesize segmentedControl;
define METRIC_INDEX 0
define IMPERIAL_INDEX 1
define FRACTION_INDEX 2
-(IBAction)toggleUnit
{
selectedUnit = [segmentedControl selectedSegmentIndex];
if (selectedUnit == METRIC_INDEX)
{
[MetricPickerController updateLabel1];
}
}
#end
MetricPickerController.h
#interface MetricPickerController : NSObject <UIPickerViewDataSource,UIPickerViewDelegate> {
UIPickerView *pickerView;
UILabel *label;
}
#property(nonatomic,retain)UIPickerView *pickerView;
#property(nonatomic,retain)UILabel *label;
-(void)updateLabel1;
#end
MetricPickerController.m
import "MetricPickerController.h"
#implementation MetricPickerController
#synthesize pickerView;
#synthesize label;
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 10;
}
-(void)updateLabel1
{
label.text = #"test"
}
the problem is that i get an error message on compiling here in the firstviewcontroller
-(IBAction)toggleUnit
{
selectedUnit = [segmentedControl selectedSegmentIndex];
if (selectedUnit == METRIC_INDEX)
{
[MetricPickerController updateLabel1]; <<<<< (MetricPickerController might not respond to +updateLabel1)!!
also if i click the toggle in IB xcode will crash with sigbart error
}
can anyone please help and advise what i have done wrong i think i have everything hooked up properly so i guess this is to do with my method declaration somehow
i know the code is incomplete at this stage but its driving me crazy trying to get rid of this error and i hope you can appreciate that i am just a learner
}
The problem is that updateLabel1 is an instance method, and you are sending it to a class (the +updateLabel1 instead of -updateLabel1 in the error message tells you this).
Since you've named your instance variables the same as the classes, you should be able to solve this by writing
[self.MetricPickerController updateLabel1];
instead - this makes it clear to the compiler you are referring to the instance variable and not the actual class.

switching views in iphone [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
switching views in iphone
I am making a client server program in which i want to switch from one view to another but i am getting an error in "clientserverprogram view.m" plz help.i also asked same question five hours ago but the answer was not satisfactory again same error is pertaining.
"clientserverprogram view.h"
#import <UIKit/UIKit.h>
#class secondview;
#interface clientserverprogramViewController : UIViewController {
IBOutlet UITextField *name;
IBOutlet UITextView *filepath;
IBOutlet UIButton *print;
IBOutlet UIButton *settings;
IBOutlet UIButton *cancel;
IBOutlet UILabel *display;
IBOutlet secondview *secondview;
}
-(IBAction) print;
-(IBAction) settings;
-(IBAction) cancel;
#property (nonatomic , retain) IBOutlet UITextField *name;
#property (nonatomic , retain) IBOutlet UITextView *filepath;
#property (nonatomic , retain) IBOutlet UILabel *display;
#end
"clientserverprogram view.m"
#import "clientserverprogramViewController.h"
#import "secondview.h"
#implementation clientserverprogramViewController
#synthesize name ,filepath,display ;
-(IBAction) print {
NSString *str = name.text;
[display setText : str];
}
-(IBAction) settings {
[self presentModalViewController: secondview animated: YES ];
"" error: expected expression before 'secondview'""
}
-(IBAction) cancel {
exit(0);
}
- (void)dealloc {
[super dealloc];
}
#end
"secondview.h"
#import <UIKit/UIKit.h>
#interface secondview : UIViewController {
IBOutlet UIView *view;
IBOutlet UIButton *back;
}
-(IBAction) back;
#end
""secondview.m""
#import "secondview.h"
#implementation secondview
-(IBAction) back {
[self.parentViewController dismissModalViewControllerAnimated: YES];
}
- (void)dealloc {
[super dealloc];
}
#end
I used your code and the problem here is your class name "secondview" and the instance you are making from it IBOutlet secondview *secondview are same. Please use different name for class names and the instances you create.
Always start with uppercase for class names and start with lowercase for class instances you create.
Hence, your class name should be SecondView and you should write IBOutlet SecondView *secondView.
Or you should just use different names. Its very confusing.