iPhone UITextField inputView error: Assignement to readonly property - iphone

I am having issues when I want to assign UIPicker as inputView of UITextField. It shows error " Assignement to readonly property". Please help as I think it is not related to property sythesizing.
I have added my code below:
#interface DriverWaitingDetails : UIViewController<UITextFieldDelegate,UIPickerViewDataSource, UIPickerViewDelegate>
{
IBOutlet UILabel *baseLabel;
IBOutlet UITableView *driverTableView;
IBOutlet UIPickerView *basePicker;
}
#property(nonatomic, retain) IBOutlet UIPickerView *basePicker;
#property(nonatomic,retain)IBOutlet UILabel *baseLabel;
#property(nonatomic,retain)IBOutlet UITableView *driverTableView;
#end
Implementation Code:-
-(void)viewDidLoad
{
basePicker=[[UIPickerView alloc] initWithFrame:CGRectMake(0,100,320, 500)];
self.navigationItem.title=#"Driver Table";
baseLabel.userInteractionEnabled = YES;
basePicker.delegate = self;
basePicker.dataSource = self;
[basePicker setShowsSelectionIndicator:YES];
baseLabel.inputView=nil;
[super viewDidLoad];
}
Attached Screenshot:-

You are setting the input view of UILabel.
You declared baseLabel as UILabel not UITextField.
IBOutlet UILabel *baseLabel;

You have declared
IBOutlet UILabel *baseLabel;
UILabel inherits from UIView : UIResponder : NSObject and the property is defined in UIResponder:
#property (readonly, retain) UIView *inputView
As the property inputView is read only, you cannot assign any value to it.

Related

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;
}

UISlider - parameter - iphone

In my application I have a UISlider where file.h is:
#interface Mapa : UIViewController {
UILabel *label;
UISlider *slider;
}
#property(nonatomic, retain) IBOutlet UILabel *label;
#property(nonatomic, retain) IBOutlet UISlider *slider;
-(IBAction)sliderValueChanged:(UISlider *)sender;
-(IBAction) OpenList:(id)sender;
-(IBAction) OpenMap:(id)sender;
And file.m:
#synthesize label;
#synthesize slider;
-(IBAction)sliderValueChanged:(UISlider *)sender {
label.text = [NSString stringWithFormat:#"%f", sender.value];
}
- (void)dealloc {
[super dealloc];
[label release];
[slider release];
}
done this to me uislider goal of the label, I get the number that's out on the label bound to the UISlider, another screen to call a map, how this value label step to the other screen?
thanks
Assuming your 'other screen' is another UIViewController, then after instantiating the new UIViewController, you would set the parameters on the new UIViewController before calling either pushViewController or presentModalViewController.
If you're using a UIStoryboard then you can set the parameters of the new view controller in 'prepareForSegue'. See this question How to pass prepareForSegue: an object for details.

type of property txtname (uiTextView *) does not match of ivar txtname(uiTextView)

// ViewController.h
#interface ViewController : UIViewController{
IBOutlet UIButton *btnname;
IBOutlet UITextView *txtname;
IBOutlet UILabel *lblname;
}
#property (retain, nonatomic) IBOutlet UITextField *txtname;
#property (retain, nonatomic) IBOutlet UILabel *lblname;
- (IBAction)Btntikla:(id)sender;
#end
//ViewController.m
#implementation ViewController
#synthesize txtname;//here it says -type of property txtname (uiTextView *) does not match of ivar txtname(uiTextView)- this mistakes
#synthesize lblname;
- (void)dealloc {
[lblname release];
[txtname release];
[super dealloc];
}
- (IBAction)Btntikla:(id)sender {
NSString *name=[txtname text];
lblname.text=name;
}
#end
//my whole program is this.it gives this error?type of property txtname (uiTextView *) does not match of ivar txtname(uiTextView)..Can you help me pls?? what is my mistake ?
That's beacause you have
#property (retain, nonatomic) IBOutlet UITextField *txtname;
and
IBOutlet UITextView *txtname;
And UITextField and UITextView are differents controls

Not able to push next view after clicking a uibutton which is on the top right of the view

i am having a view consisting of a tableview and a uibutton like this
when i click on button "add" a new class/xib named "Locsetting" should be open.which i am not able to do.
my code: .h file
#interface LocationViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
UITableView *table;
NSMutableArray *menuList;
LocSetting *locSetting;
IBOutlet UIButton *addbutton;
}
#property (nonatomic,retain) NSMutableArray *menuList;
#property (nonatomic,retain) IBOutlet UITableView *table;
#property (nonatomic,retain) LocSetting *locSetting;
#property (nonatomic, retain) IBOutlet UIButton *addbutton;
-(IBAction)gotoLocSetting:(id) sender;
#end
My .m :
#synthesize addbutton;
-(IBAction)gotoLocSetting:(id) sender {
NSLog(#"gotoLocSetting Entered");
locSetting = [[LocSetting alloc]
initWithNibName:#"LocSetting"
bundle:nil];
//locationViewController.menuList = [menuList objectAtIndex:indexPath.row];
[self.navigationController pushViewController:locSetting
animated:YES];
[locSetting release];
}
what wrong i am doing?or please guide me!
Thanks
On a quick look, there might be one of the following 3 problems:
Is your IBAction linked to the button's outlet?
If not, try removing LocSetting *locSetting; and its property/synthesize. Next, change your line down there to: Locsetting *locSetting = [[LocSetting alloc] initWithNibName:#"LocSetting" bundle:nil];
If that doesn't work, try changing that to: Locsetting *locSetting = [[LocSetting alloc] initWithNibName:nil bundle:nil];
Make sure the IBAction is connected properly to the button. And I think its better to have IBOutlet UIButton *addbutton; alone and #property (nonatomic, retain) UIButton *addbutton;

is not a kind of ... as specified by the outlet type

I'm using a derived UISearchBar because I have to set the font size:
#import <UIKit/UIKit.h>
#interface SearchBar : UISearchBar
{
UITextField *searchField;
}
#property (nonatomic, retain) UITextField *searchField;
- (void) setFontSize: (NSInteger) size;
#end
In my ViewController the Outlet is defined:
#interface DictViewController : UIViewController <UIApplicationDelegate, UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *myTableView;
IBOutlet SearchBar *mySearchBar;
NSMutableArray *searchResults;
}
#property (nonatomic, retain) IBOutlet UITableView *myTableView;
#property (nonatomic, retain) IBOutlet SearchBar *mySearchBar;
...
InterfaceBuilder don't let me connect the SearchBar to mySearchBar.
If I change the outlet class to UISearchBar, IB let me connect to mySearchBar. When I change the class back to SearchBar, the connection remains, but with the warning "The 'mySearchBar' outlet of FilesOwner is connected to 'SearchBar' but 'UISearchBar' is not a kind of 'SearchBar' as specified by the outlet type"
What's wrong? Any idea what I can do?
This might fix the problem.
In IB, select the search bar and go to the Identity pane of the inspector window. In the class dropbox, choose SearchBar instead of UISearchBar.