I want to create a UIPickerView with the easiest way possible, because all of what I know Is not enough to help me
Ok what I ment is that I am trying to get a UISegmented that will end up creating a UIPickerView but I want to create a UIPickerView that shows up when I select one of the segments in the segmented control animated, and also the pickerview is supposed to use an array that has colors like red green blue
Ok what I ment is that I am trying to get a UISegmented that will end up creating a UIPickerView but I want to create a UIPickerView that shows up when I select one of the segments in the segmented control animated, and also the pickerview is supposed to use an array that has colors like red green blue
For your UISegmentedControl, you'll need to register target-action methods. For example:
[segmentedControl addTarget:self
action:#selector(updatePicker:)
forControlEvents:UIControlEventValueChanged];
Inside of updatePicker, set a variable that corresponds to whatever you want to show in your picker. Then, to your picker instance (you should only have one instance of this class), send the reloadAllComponents message. This will update the picker by querying the delegate for new data. In your delegate (which can probably all be the same class), you'll want to check the value of the variable you set in updatePicker to determine what data to return to the picker.
This page has video and instructions on how to add UIPickerView programmatically in Swift, i.e. it does not use Interface Builder or Story Board, everything is done in a few lines of code.
http://www.appswiftprogramming.com/pg/2171/UIPickerView_Programmatically
You can add your custom view in the UIPickerView if you want something more advanced. It shows that too.
Related
i have a UITableView where i want one cell(database row) needs to be default,
So I am thinking of two options
in TableView upon clicking a cell, change accessoryType to mark just like ringtone selection in settings app
when user enters data, add an option (like radio button or segmented control) to make that cell (database row) as default one
I feel first option is good but we can implement code for that only in didSelectRowAtIndexPath but i need to jump to another view when user click on a cell.
So please give me an idea how to accomplish this
One idea iam thinking is adding an edit button but don't know whether its possible or not.
Thanks
Not sure if i understand your question correctly , but according to what i understand you want a table view in which many values will be there , and you want one value to be default which can be changed later.
According to me these ways would be pretty good,
Changing the accessorytype of the tableViewCell. (Most common way)
Changing the Highlighted property of the cell on loading the tableView.
Adding some image then setting the image as the background view of the selected cell.
Adding custom image view (such as tick or something and adding to the cell).
this code can be put in the viewDidload so your default selected value appears.
Hope this helps.
Don't know what you mean by default. I'm assuming you mean already selected. You might just want to set the accessoryType to the checkbox. That would be Apple's way of doing it.
I would like to add a toolbar with a label entitled "Save your search?" on the left and a button "Save" on the right that triggers a specific action when tapped. How could I do that programmatically, especially I want this Toolbar to show up only when a particular View is loaded on a screen but not on every view.
Also, I want the toolbar to have a static image as background. "Save" button will also have a static image for background
Just to check; why do you need to add this toolbar of sorts onto a TableView? Depending on how you've set things up; and specially seeing that you need to conditionally hide/show this toolbar, might be easier to add it outside the tableView (just above it I guess).
Seeing as you need to hide/show this toolbar at will; guess you can simply use a UIView for it and add the UIButtons on top as subviews; --> declare it as a property in the .h file so that it can be freely accessed in the .m file whenever you need to hide / show it.
Did you need help on some specific issue related to this perhaps; or would this serve as a goo enough starting point?
I want to make a small area to present some information in the middle of a UIToolbar and was wondering what the best way to do this is.
I need to show some text and a graphic, both of which need to be updated (around every 3 seconds) as new information arrives. The graphic is similar to the iPhone signal strength indicator, so it can be either custom drawn or selected from one of 3 graphics (low, medium, high strength).
I'll probably use initWithCustomView: to create a UIBarButtonItem, although I would like the view to be clickable (to allow the user to change the information shown).
What's the best way to make that view? Can I use a NIB, or do I need to do custom drawing in the view? What's the best way to update the buttons? I'm assuming that I'll have to remake the toolbarItems array each time and set it when the information changes. Is there a cleaner way to do this? Thanks.
Using initWithCustomView: sounds like a good way to go. You can create your custom view any way you want: with a NIB, by drawing it, even using images. It can also have its own subviews. It can be any object that inherits from UIView. (So, if you wanted, you could even make it actionable by using a UIButton, a custom UIControl, or a custom UIView with a gesture recognizer attached.)
You shouldn't have to remake toolbarItems (or, for that matter, do anything with it after you've added all your button items) if you just keep a pointer to your custom view UIBarButtonItem. It could be an instance variable. Then, to update the custom view, you could access it as you would any other view. I've never actually tried this, but I can't see any problem with doing it.
You sound like you had it mostly figured out. Hope this is helpful.
I needed the same solution and was hoping for some code examples from you. So I ended up doing it all in IB and the steps are here as follows:
Create UItoolbar in IB with no Items. (A Bar Button Item will be added again once you add the UIView)
Add UIView as subview of UIToolbar
Add UILabels to subview of UIView that is already a subview of the UIToolbar.
Create IBOutlets from UIToolbar, UIView and each UILabel and then you can reference the labels in your app.
I did set the backgrounds to clearColor so the text appears on top of UIToolbar without any box or borders.
And the text updates dynamically which was the desired outcome.
Hope this helps someone as this has been eluding me for a while.
I have assigned a button (holdCardOne) an image in the interface builder. What I want to do is change the image when a card is selected from a picker. I have the picker working and selecting the card but I need to change the image on the original selected button to resemble the selection.
Can I do this using code?
Does it matter I assigned the image in the interface builder or does it have to be all done by code?
You should be able to change the button image using the setImage:forState: method of the UIButton class. See the UIButton class reference for more info.
In terms of using the Interface Builder, it would be safe to set the initial image in that, but you'll need to handle things yourself from that point onwards. (e.g.: If a user can un-associate an image with a button, you'll need to set an appropriate image programatically as above.)
You can do it either in code or in the interface builder or both!
InterfaceBuilder lets you assign images for each button state (normal, highlighted, selected) -- so it could be as easy as assigning images for each state, and then simply changing the state in your code.
Alternatively, you can set the image directly, simply by saying:
[myButton setImage: (someImage) forState: UIControlStateNormal];
You might want to also set this image for the other buttons states (highlighted, selected), it all depends on how you want the interface to behave.
It doesn't matter that it was assigned in Interface Builder. All you need to do is this:
[yourButtonName setImage:yourNewImageName forState:UIControlStateNormal];
You'll also likely want to set an image for
UIControlStateHighlighted
and possibly for
UIControlStateDisabled
and
UIControlStateSelected
I am trying to create something that uses the idea of the UIPopOverController, I mean, have that speech bubble anchor pointing to the button who triggered the method.
The problem is that I am using a UISegmentedControl...
How do I get the id of the button that was tapped on a UISegmentedControl, so I can determine its position and generate the anchor?
thanks for any help.
Look at SegmentViewController.{h,m} in the UICatalog sample project.
The sample code sets up the view using code.
This line
[segmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
is where the magic happens.
- (void)segmentAction:(id)sender
{
//NSLog(#"segmentAction: selected segment = %d", [sender selectedSegmentIndex]);
}
You can also do this in Interface Builder
Assuming that you have (IBAction)segmentAction:(id)sender declared in your ViewController and that the Files Owner is your ViewController, right-click on the UISegmentedControl and make the connection between the UIControlEventValueChanged event to the Files Owner segmentAction
UISegmentedControl acts like a "single" button. It is a single object placed in a single frame unlike the toolbar items which are an array of objects placed in their own frames. A typical usage pattern is to dispatch a message inside a switch statement in your segmentAction method.
I see two options.
Option A: Implement a custom view that contains an array of UIButton controls. The action for the UITouchUpInside event for the all of the buttons can point to the same method in your controller. Then implement a buttonPressed:(id)sender which you can ask the sender for it's frame and location to use to create your new view on top. --> Complicated
Option B: You can calculate the position of the new subview using an offset calculated from selectedSegmentedIndex, widthForSegmentAtIndex:, and contentOffsetForSegmentAtIndex:. Really not much different than calculating from the bounds of any view. --> Easier