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.
Related
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;
}
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.
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.
Hey!
I am trying to hide a UIButton after it is pressed
This is my .h code:
#import <UIKit/UIKit.h>
#interface TemplateTestViewController : UIViewController { }
- (IBAction)ButtonPressed;
IBOutlet UIButton *sample; #property (nonatomic, retain) IBOutlet UIButton
*sample;
#end
This is my .m code:
#import "TemplateTestViewController.h"
#import "Page.h"
#implementation TemplateTestViewController
#synthesize sample;
-(IBAction) ButtonPressed{
if ( ([sample.selected=YES]))
{
sample.hidden = YES;
}
I get four errors and the code does not work. What am I doing wrong? I am new so some sample code would be much appreciated!
you have issue in the your .h file with #interface declaration. use below
#import <UIKit/UIKit.h>
#interface TemplateTestViewController : UIViewController {
IBOutlet UIButton *sample;
}
#property (nonatomic, retain) IBOutlet UIButton *sample;
- (IBAction)ButtonPressed;
#end
And in your .m class
-(IBAction) ButtonPressed {
if(sample.selected == YES)
{
sample.hidden = YES;
}
}
I am trying to load a UIView with multiple data. The problem is data is not displays in first load but loads it in subsequent clicks. Can you help me trace the problem.
FirstViewController.h
#import <UIKit/UIKit.h>
#class SecondViewController;
#interface FirstViewController : UIViewController {
IBOutlet SecondViewController *mySecondViewController;
IBOutlet UIImageView *myimage1;
IBOutlet UIImageView *myimage2;
IBOutlet UILabel *mylabel1;
IBOutlet UILabel *mylabel2;
}
#property (nonatomic, retain) IBOutlet SecondViewController *mySecondViewController;
#property (nonatomic, retain) IBOutlet UIImageView *myimage1;
#property (nonatomic, retain) IBOutlet UIImageView *myimage2;
#property (nonatomic, retain) IBOutlet UILabel *mylabel1;
#property (nonatomic, retain) IBOutlet UILabel *mylabel2;
- (IBAction)bringNextView:(id)sender;
- (IBAction)bringNextView2: (id)sender;
#end
FirstViewController.m
#import "FirstViewController.h"
#import "SecondViewController.h"
#implementation FirstViewController
#synthesize mySecondViewController,myimage1, myimage2, mylabel1, mylabel2;
- (IBAction)bringNextView:(id)sender {
mySecondViewController.name.text = #"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:#"Paul.png"];
mySecondViewController.statmsg.text = #"Doing iPhone Development";
[[self navigationController] pushViewController:mySecondViewController animated:YES];
}
SecondViewController.m
#import "SecondViewController.h"
#implementation SecondViewController
#synthesize myimageview, name, statmsg
- (void)viewDidLoad {
[self setTitle:#"Details"];
[super viewDidLoad];
}
Properties are not coming for the first time. But are displays after returning from view and then loading view again.
I am loading SecondViewController from FirstViewController.
Hi I have solved this. Actually I was pushing my view controller after setting up the property and that caused this issue.
Instead of :
mySecondViewController.name.text = #"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:#"Paul.png"];
mySecondViewController.statmsg.text = #"Doing iPhone Development";
[[self navigationController] pushViewController:mySecondViewController animated:YES];
It should be :
[[self navigationController] pushViewController:mySecondViewController animated:YES];
mySecondViewController.name.text = #"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:#"Paul.png"];
mySecondViewController.statmsg.text = #"Doing iPhone Development";