I want to show a UIPickerView and not the keyboard when I edit a UITextField. I tried this:
- (void)viewDidLoad
{
[super viewDidLoad];
depCityField.inputView=pickerDestinations;
comeCityField.inputView=pickerDestinations;
}
It doesn't work, but with UIDatePicker it works fine...
I have created an example programmatically for your reference. I really hope this helps you. This is the source.
Sounds like your textFields dont have the delegate set. You need to set the UIViewController as the delegate to the textFields.
Your viewDidLoad should probably look like this:
- (void)viewDidLoad()
{
[super viewDidLoad];
depCityField.delegate = self;
comeCityField.delegate = self;
depCityField.inputView=pickerDestinations;
comeCityField.inputView=pickerDestinations;
}
Related
Okay it seems like I have made some mistakes and I did not get it with pointer and initializations by now...
Here is the problem :
I have a UIViewController for a registration process called : RegisterViewController
It calls a method in its ViewDidLoad :
[self performSelector:#selector(activateUsernamePopover) withObject:nil afterDelay:0.1];
This method looks like this :
- (void) activateUsernamePopover {
PopoverViewController *popcontroller = [[PopoverViewController alloc] init];
popcontroller.title = nil;
[popcontroller setPopoverText:#"Test"];
FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:popcontroller];
popover.arrowDirection = FPPopoverArrowDirectionUp;
popover.border = NO;
popover.tint = MgoGreyTint;
[popover setShadowsHidden:true];
[popover presentPopoverFromView:_usernameInput]; }
This will made a Popover visible. This works great.
But I Do have a few more TextFields where I want to show a Popover with a different text.
So I made a method in the PopoverViewController called setPopoverText :
- (void)setPopoverText:(NSString *)text {
[_popoverLabel setText:text];
[_popoverLabel setNeedsDisplay]; }
I call it in my activateUsernamePopover method :
[popcontroller setPopoverText:#"Test"];
And there is the problem.
I can log the text in the PopoverViewControllers method setPopoverText its fine.
But it did not change the text. I logged the _popoverLabel like this :
NSLog(#"%#",_popoverLabel);
and its (null).
I know there is some issue with the pointer or the instance of PopoverViewController I am working with, but objective c is not that clear to me yet.
Anyone got some answers for me ?
How can I change the Text of that UILabel ?
I also could imagine giving the Text to the Controller while instancing it.
Something like that :
PopoverViewController *popcontroller = [[PopoverViewController alloc] initWithPopoverText:#"Test"];
But I don´t know how. I don´t need to change the Text while the popover is visible. It will be released when the user taps in the TextField or elsewhere.
Thanks so far.
Since the UILabel is not created yet when you call init method. the way to do it is to keep text in the NSString property.
In you PopoverViewController, create the init method like this
#interface ViewController : UIViewController
- (id)initWithPopoverText:(NSString *)text;
#end
In the implementation file, keep hold of the text in the property and on viewDidLoad, you could set the text to the label.
#interface PopoverViewController ()
#property (nonatomic) NSString *popoverText;
#end
#implement PopoverViewController
- (id)initWithPopoverText:(NSString *)text {
self = [super init];
if (self) {
_popoverText = text;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
//set label.text here
self.popoverLabel.text = self.popoverText;
}
#end
I have implemented a basic slider using iCarousel iOS library but i dont know how to make it as a Auto slider instead of manual swipe sliding.
Here is my sample project code Pls help me
Code
When i searched in google i got this link,but i didnt understand anything
https://github.com/nicklockwood/iCarousel/issues/84
This solved my problem
in ViewDidAppear() i have added following line
-(void)viewDidAppear:(BOOL)animated
{
sliderCount=0;
[super viewDidAppear:animated];
[NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:#selector(runMethod) userInfo:nil repeats:YES];
}
-(void)runMethod
{
[self.carousel scrollToItemAtIndex:sliderCount animated:YES];
if(sliderCount== 7)
{
sliderCount=0;
}
else
{
sliderCount++;
}
}
In your ViewDidLoad method in your Viewcontroller.
- (void)viewDidLoad
{
[super viewDidLoad];
//configure carousel
carousel.type=iCarouselTypeCylinder;
carousel.autoscroll=0.4;
}
Looking at the github link, I assume you want to autoscroll to an item upon view.
You have defined the function
- (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated
However this isn't part of the iCarousel delegate, its already defined as part of the class, therefore you just need to call it. Putting it in viewDidAppear would seem appropriate if you wanted it to auto scroll to a particular index when your view controller was presented to the user. Simply add the method below.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// The index of 3 was just chosen as an example
NSInteger chosenIndex = 3;
[self.carousel scrollToItemAtIndex:chosenIndex animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type=iCarouselTypeCylinder;
carousel.autoscroll=0.8;
[carousel reloadData];
}
I am subclassing an UIButton which is going to be present in all of my app's ViewControllers, kinda Navigation Button. I would like just to put it to my VC and apply custom class, without any code in ViewController itself. So, the questions:
1. is it possible?
2. I am using this code now in my UIButton custom class. What is wrong?:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self addTarget:self action:#selector(didTouchButton) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
- (void)didTouchButton {
NSLog(#"YEAH, it works, baby!");
}
UPD: seems that even initWithFrame method is not being called at all.
Loading from the nib I think.The initWithFrame method doesn't work if not called programatically.
Try -awakeFromNib Method
See this question
I have an UITextField to search the word that typed there. I set the returnKeyType as UIReturnKeySearch. But I couldn't figure how to bind a function that I created, to the "Search" button at the keyboard.
self.searchWord.returnKeyType=UIReturnKeySearch;
How can I do that? Thanks.
If I'm understanding correctly you need to implement the UITextfield delegate:
In your header file
#interface MyViewController : UIViewController <UITextFieldDelegate>
in viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
self.searchTextField.delegate = self;
}
Then implement the delegate method.
- (BOOL)textFieldShouldReturn:(UITextField *)aTextfield {
// Only do search when user hits return key on the search textfield.
if ([aTextfield isEqual:self.searchTextField]) {
// Method that does the search.
[self doSearch];
}
return YES;
}
I am creating a customView and for example, would like to set the text color of the label and initialise the text of the label.
The initWithFrame is the generic function.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
I have tried initialising the label in the initWithFrame, but it doesn't work. But when I do it in awakeFromNib, it allows me to set the text color but not the text(this value comes from a dictionary)
-(void)awakeFromNib
{
//setting of the label textcolor
}
What would be the correct way to initialise the color and text of labels and other stuff?
Need some suggestions and guidance...
Edit:
-(void)viewDidLoad
{
[self updateViewWithDictionary:dictPassed];
}
Something like this?
What I do in some project's is expose a public method like so:
- (void)updateViewWithDictionary:(NSDictionary *)confDictionary;
In that dictionary I pass the parameters I want, and inside the UIView's subview I update it according to what I want.
Edit 1:
Read wrongly your question, sorry. You have a custom UIView that you would like to be updated when your UIViewController starts, or when you actually use it. So you should have something like this:
#interface MyView : UIView
{
}
- (void)updateViewWithDictionary:(NSDictionary *)confDictionary;
#end
And from your viewDidLoad:
-(void)viewDidLoad
{
[self.customView updateViewWithDictionary:dictPassed];
}