Skip to content
Snippets Groups Projects
Commit 22f43c24 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

remove last UIActionSheet

parent a2586287
No related branches found
No related tags found
No related merge requests found
...@@ -72,30 +72,39 @@ ...@@ -72,30 +72,39 @@
std::vector<onelab::string> string; std::vector<onelab::string> string;
onelab::server::instance()->get(string, [name UTF8String]); onelab::server::instance()->get(string, [name UTF8String]);
if(string.size() < 1) return; if(string.size() < 1) return;
UIActionSheet *popupSelectValue = UIAlertController *alertController =
[[UIActionSheet alloc] initWithTitle:[Utils getStringFromCString:string[0].getLabel().c_str()] [UIAlertController alertControllerWithTitle:nil message:nil
delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil preferredStyle:UIAlertControllerStyleActionSheet];
otherButtonTitles:nil]; [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
}]];
std::vector<std::string> choices = string[0].getChoices(); std::vector<std::string> choices = string[0].getChoices();
for(int i = 0; i < choices.size(); i++) for(unsigned int i = 0; i < choices.size(); i++){
[popupSelectValue addButtonWithTitle:[Utils getStringFromCString:choices[i].c_str()]]; NSString *t = [Utils getStringFromCString:choices[i].c_str()];
[popupSelectValue addButtonWithTitle:@"Cancel"]; [alertController addAction:[UIAlertAction actionWithTitle:t
[popupSelectValue setCancelButtonIndex:popupSelectValue.numberOfButtons - 1]; style:UIAlertActionStyleDefault
[popupSelectValue showInView:button]; handler:^(UIAlertAction *action) {
[self updateString:string[0] withValue:choices[i]];
[button setTitle:[Utils getStringFromCString:choices[i].c_str()]
forState:UIControlStateNormal];
}]];
}
[alertController setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alertController popoverPresentationController];
popPresenter.sourceView = button;
popPresenter.sourceRect = button.bounds;
// FIXME: is traverseResponderChainForUIViewController a good idea?
[[Utils traverseResponderChainForUIViewController:button] presentViewController:alertController
animated:YES completion:nil];
} }
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex -(void) updateString: (onelab::string)s withValue:(std::string)v
{ {
std::vector<onelab::string> string; s.setValue(v);
onelab::server::instance()->get(string, [name UTF8String]); onelab::server::instance()->set(s);
if(string.size() < 1) return;
if(buttonIndex < string[0].getChoices().size()){
std::string selected = string[0].getChoices()[buttonIndex];
string[0].setValue(selected);
onelab::server::instance()->set(string[0]);
[super editValue]; [super editValue];
} }
}
-(void)refresh -(void)refresh
{ {
...@@ -145,30 +154,25 @@ ...@@ -145,30 +154,25 @@
std::vector<onelab::number> numbers; std::vector<onelab::number> numbers;
onelab::server::instance()->get(numbers, [name UTF8String]); onelab::server::instance()->get(numbers, [name UTF8String]);
if(numbers.size() < 1) return; if(numbers.size() < 1) return;
UIAlertController *alertController; UIAlertController *alertController =
UIAlertAction *destroyAction; [UIAlertController alertControllerWithTitle:nil message:nil
alertController = [UIAlertController alertControllerWithTitle:nil message:nil
preferredStyle:UIAlertControllerStyleActionSheet]; preferredStyle:UIAlertControllerStyleActionSheet];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
}]];
std::vector<double> choices = numbers[0].getChoices(); std::vector<double> choices = numbers[0].getChoices();
for(unsigned int i = 0; i < choices.size(); i++) for(unsigned int i = 0; i < choices.size(); i++){
[alertController NSString *t = [Utils getStringFromCString:numbers[0].getValueLabel(choices[i]).c_str()];
addAction:[UIAlertAction [alertController addAction:[UIAlertAction actionWithTitle:t
actionWithTitle:[Utils getStringFromCString:numbers[0].getValueLabel(choices[i]).c_str()] style:UIAlertActionStyleDefault
style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[self updateNumber:numbers[0] withValue:choices[i]]; [self updateNumber:numbers[0] withValue:choices[i]];
[button setTitle:[Utils getStringFromCString:numbers[0].getValueLabel(i).c_str()] [button setTitle:[Utils getStringFromCString:numbers[0].getValueLabel(i).c_str()]
forState:UIControlStateNormal]; forState:UIControlStateNormal];
}]]; }]];
}
destroyAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
// do nothing
}];
[alertController addAction:destroyAction];
[alertController setModalPresentationStyle:UIModalPresentationPopover]; [alertController setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alertController popoverPresentationController]; UIPopoverPresentationController *popPresenter = [alertController popoverPresentationController];
popPresenter.sourceView = button; popPresenter.sourceView = button;
popPresenter.sourceRect = button.bounds; popPresenter.sourceRect = button.bounds;
...@@ -181,7 +185,6 @@ ...@@ -181,7 +185,6 @@
{ {
n.setValue(v); n.setValue(v);
onelab::server::instance()->set(n); onelab::server::instance()->set(n);
[super editValue]; [super editValue];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment