Last active
June 14, 2019 09:06
-
-
Save suda/4722708 to your computer and use it in GitHub Desktop.
Multiple Row Selection in UIPickerView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { | |
UITableViewCell *cell = (UITableViewCell *)view; | |
if (cell == nil) { | |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; | |
[cell setBackgroundColor:[UIColor clearColor]]; | |
[cell setBounds:CGRectMake(0, 0, cell.frame.size.width - 20, 44)]; | |
cell.tab = row UITapGestureRecognizer * singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleSelection:)]; | |
singleTapGestureRecognizer.numberOfTapsRequired = 1; | |
[cell addGestureRecognizer:singleTapGestureRecognizer]; | |
} | |
if ([selectedItems indexOfObject:[NSNumber numberWithInt:row]] != NSNotFound) { | |
[cell setAccessoryType:UITableViewCellAccessoryCheckmark]; | |
} else { [cell setAccessoryType:UITableViewCellAccessoryNone]; | |
} cell.textLabel.text = [datasource objectAtIndex:row]; | |
return cell; | |
} | |
- (void)toggleSelection:(UITapGestureRecognizer *)recognizer { | |
NSNumber *row = [NSNumber numberWithInt:recognizer.view.tag]; | |
NSUInteger index = [selectedItems indexOfObject:row]; | |
if (index != NSNotFound) { | |
[selectedItems removeObjectAtIndex:index]; | |
[(UITableViewCell *)(recognizer.view) setAccessoryType:UITableViewCellAccessoryNone]; | |
} else { [selectedItems addObject:row]; | |
[(UITableViewCell *)(recognizer.view) setAccessoryType:UITableViewCellAccessoryCheckmark]; | |
} | |
} |
Thanks for your response :)
Got understanding of the issue already.
Regards
…On Thu, Jun 13, 2019 at 4:15 PM Wojtek Siudzinski ***@***.***> wrote:
@08irfan <https://github.com/08irfan> sure! What is your question?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/4722708?email_source=notifications&email_token=ABPEIWN5AHLCZ3DXQGASX5LP2IT5RA5CNFSM4HXTRA3KYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFTTIE#gistcomment-2942594>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABPEIWML64WXTBN7CD2A34LP2IT5RANCNFSM4HXTRA3A>
.
--
*Muhammad Irfan*
Virtual Proz
+92332-6990646
Skype: mirfan191
<http://www.facebook.com/irfan191>
<http://www.linkedin.com/in/muhammad-irfan-85958745>
Thanks @suda for the reply.
issue resolved already :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@08irfan sure! What is your question?