UIPickerView multi selection on ios7 - forms

I need a picker view witch i can select multi values, like the "select input" in HTML :
In ios6, i did it with a custom view created in the UIPickerViewDelegate (pickerView:viewForRow:forComponent:reusingView:) and a UIButton in each row, but since ios7, the custom view don't received the touch event.
Is it possible to do it in ios7 ?

DrDisc has confirmed that it is not possible to handle a touch event directly from a row view since ios7.
But it is possible to :
add a Tap Gesture to the UIPickerView
retrive the selected view
call a method to check / uncheck the row
int row = [self.pickerView selectedRowInComponent:0];
UIView *rowView = [self.pickerView viewForRow:row forComponent:0];
if([rowView isKindOfClass:[YouCustomView class]])
{
[(YouCustomView*)rowView toggleCheck];
[self.pickerView reloadAllComponents];
}
I think it is more natural than a button to check/uncheck, but we lost the ability to select an other row with a tap on it.

As far as I know, this is not possible. One option is to utilize UIPickerView's delegate method:
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
You could store the selection in an array and change the text passed through from the data source to some sort of selection text ("x Selection 1").
Alternatively, you could have a 'select item' button that would add the currently displayed value to the selected array.
When the user clicks a button you can then look through the selected array for those that were selected.
These may not be the best methods, they're just my initial thoughts on it.

Related

How to set selection indicator on passing object Index in picker View

I have 3 buttons on one View of UIViewController. On each button click event i called same picker view with different object values.
how to set the selection indicator on last object index for particular
button.?
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
Selects a row in a specified component of the picker view.
Source
In button click event you can make use of this.
selectRow:inComponent:animated: - Helps you select particular row in the picker.
numberOfRowsInComponent: - Returns the count of rows in the particluar component.
So inorder to select the last object index, you can make use of this.
[self.pickerView selectRow:[self.pickerView numberOfRowsInComponent:0] inComponent:0 animated:NO];
You can do this using following snippet
[self.pickerView selectRow:MAX_VALUE inComponent:0 animated:NO];
where MAX_VALUE = total no. of rows in component - 1;
Enjoy Programming !!

How to add an overlay to view the selected values in UIPickerView?

I have created a UIPickerView and I want to add an overlay view to show the user what he has selected. I don't know how to add it. Is there any property for that?
For example when we are selecting a date some overlay view will be there in the middle of UIPickerView, How should I get that ?
like: http://www.inexika.com/blog/Customizing-UIPickerView-UIDatePicker
In the UIPickerView , define
Add
pickerView.showsSelectionIndicator = YES;
and use the following method :-
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
}
Now in this add a UIView which you can call here, or just allocate it here itself adding what you want to addSubView in the UIView. Hope this much information is sufficient otherwise please tell . Thanks :)

How to disable a insert button for a Tableview Cell

I want to make a list so that users can add items to their favorites. I used uitableviewcelleditingstyleinsert for my tableview. When a user taps an insert button which has a + sign, the item will be added to the favorites list. However, I want each item in the favorites list to be unique, so I when a button is tapped, I want it to automatically become grayscale. How could I set this up in my app?
This is completely possible, but not the way you're going about it. You need to create your own accessoryView with the plus sign image, use - (void) accessoryButtonTapped: (UIControl *) button withEvent: (UIEvent *) event to know when it's been tapped and then change the UITableViewCell's accessory view based on the subsequent change to your data source.
//in your cell creation
UIImageView *i = nil;
if(cellAlreadyUsed)
i = [[UIImageView alloc] initWithImage:#"your_gray_image"];
else
i = [[UIImageView alloc] initWithImage:#"your_green_image"];
cell.accessoryView = i;
[i release];
- (void) accessoryButtonTapped: (UIControl *) button withEvent: (UIEvent *) event {
//handle changing your data source to reflect that cell was used and reload your table
}
If u want every item unique apply logic before inserting it to array.
Compare ur array items with the current item, if match with array item break the loop, u can show an alert also, if not add item to the array list.
It will be a tedious task to customize the insert button.

iPhone : How to create expanadable table view?

I want to create expandable table view.
I found one link which is same as I want.
But I want to create my own table view (Dont want to implements this github code).
How do I achieve this type of functionality ?
See this nice tutorial:
Table View Animations and Gestures
Demonstrates how you can use animated updates to open and close sections of a table view for viewing, where each section represents a play, and each row contains a quotation from the play. It also uses gesture recognizers to respond to user input: * A UITapGestureRecognizer to allow tapping on the section headers to expand the section; * A UIPinchGestureRecognizer to allow dynamic changes to the height of table view rows; and * A UILongPressGestureRecognizer to allow press-and-hold on table view cells to initiate an email of the quotation.
I came across similar feature, to build it a rough algorithm will be:
implement the uitableviewdelgate and uitableviewdatasource protocols
create a global variable expandedSectionIndex = -1;
= -1 represents all collapsed.
= 0 represents expandedSectionIndex.
//the following protocol definitions will take care of which section is to be expanded.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(expandedSectionIndex == section)
return [self.dataArray[section] count];
else
return 0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if(self.dataArray)
return [self.dataArray count];
}
define custom header views in – tableView:viewForHeaderInSection:
buttons having frame equivalent to header view frame
set button tag property with value of section number.
associate all buttons with selector - (void)expand:(id) sender;
- (void)expand:(id) sender
{
expandedSectionIndex = [sender tag];
[self.tableView reload];
}
for more detail enter link description here

UIPickerView realtime update on TextField

As soon as I scroll the PickerView (or) UIDatePicker, I need the value to get displayed on a TextField :
While Scrolling. Even when the picker is moving the text field should update itself. Is it possible ?
On the event that the Picker stops moving and comes to rest. Is there an event for the PickerView to come to rest so that I could update the textField (as soon as the pickerView comes to rest).
// I do not wish to use the TextFieldDidEndEditing
// I want the textField to update itself when the picker view comes to rest.
It would be helpful if anyone could solve 1) and 2)
(1) might not be possible. For (2), you can use the delegate method pickerView:didSelectRow:inComponent. Let me know if you need any help with this.
For UIPickerView
(1) Implement pickerView:titleForRow:forComponent,
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
// Every time the picker view is rotated, this method will be called to fetch the title.
NSInteger selectedRow = [pickerView selectedRowInComponent:0];
// Get selected row like above and process data and update text field.
[..] // Process the title
return the title.
}
(2) This is more obvious.
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// You have the selected row, update the text field.
}
For the first question, this isn't possible with the default control however there is nothing to stop you writing your own and simulate the effect using touchesMoved etc...