Just a few points before I start: I have just taken over this code I have little to no experience in iOS code Consider me a noob at this so go easy on me :P
I have some code below, which used to show a UIActionSheet
. In iOS 8 UIActionSheet has been removed (Thanks apple!) so I have started to change it all to use UIAlertController
...
I ran into many problems which I have solved, now I am completely confused and need some experienced help from you guys and girls....!
Now as you can see the UIAlertController
is being displayed but the UIView is places incorrectly and because of this the controls are impossible to use! You can drag the numbers as expected but it's not as easy...
There are three controllers as you can see, one for choosing a date time, one for number of passengers and the other for choosing a vehicle type.
I just need a nice simple fix that will work on all iOS8 phones and it can be slightly dodgy as we are about to hire someone to re-write the entire code as the code is pretty bad overall and we want to redesign the app from the bottom up.
If you want any more information do let me know, once again my iOS coding experience is very small ( I Do want to learn as I am enjoying it, albeit not as much as Android)
else if (selectedTableField == travelTimeText || selectedTableField == noPassengers || selectedTableField == carType) {
// setup actionsheet to contain the UIPicker
if (version < 8)
{
actionSheet = [[UIActionSheet alloc] initWithTitle:@" "
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet showInView:self.view];
}
if (version >= 8)
{
alertController = [UIAlertController alertControllerWithTitle:@"title"
message:@"messages"
preferredStyle:UIAlertControllerStyleAlert];
}
//CGRect actionSheetBounds = CGRectMake(0,0,320 + offset, 570);
CGRect actionSheetBounds;
if (selectedTableField == travelTimeText)
// actionSheetBounds = CGRectMake(0,0,320 + offset, 655);
if (version >= 8)
{
[alertController.view setBounds:actionSheetBounds];
}
else
{
[actionSheet setBounds:actionSheetBounds];
}
UIView *bgView = [[UIView alloc] initWithFrame:actionSheetBounds];
if (version < 7)
bgView.backgroundColor = [[[ConfigManager sharedInstance].skin valueForKey:@"popupBackgroundColour"] toUIColor];
UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// swap asap and select around if on travel time picker
if (selectedTableField == travelTimeText) {
doneBtn.frame = CGRectMake(10+bOffset, 305, 300, 40);
} else {
doneBtn.frame = CGRectMake(10+bOffset, 250, 300, 40);
}
[doneBtn addTarget:self action:@selector(pickerDone:) forControlEvents:UIControlEventTouchUpInside];
[doneBtn setBackgroundImage:[UIImage imageNamed:@"button_large.png"] forState:UIControlStateNormal];
[doneBtn setTitle:@"Select" forState:UIControlStateNormal];
doneBtn.titleLabel.font = [UIFont boldSystemFontOfSize:19];
doneBtn.titleLabel.textColor = [[[ConfigManager sharedInstance].skin valueForKey:@"popupButtonFontColour"] toUIColor];
[bgView addSubview:doneBtn];
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320 + offset, 20)];
title.font = [UIFont boldSystemFontOfSize:12];
title.backgroundColor = [UIColor clearColor];
title.textAlignment = UITextAlignmentCenter;
title.textColor = [[[ConfigManager sharedInstance].skin valueForKey:@"popupLabelFontColour"] toUIColor];
if (selectedTableField == travelTimeText) {
title.text = @"Booking Time";
UIButton *asapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
asapBtn.frame = CGRectMake(10 +bOffset, 250, 300, 40);
[asapBtn addTarget:self action:@selector(pickerAsap:) forControlEvents:UIControlEventTouchUpInside];
[asapBtn setTitle:@"As soon as possible" forState:UIControlStateNormal];
[asapBtn setBackgroundImage:[UIImage imageNamed:@"button_large.png"] forState:UIControlStateNormal];
asapBtn.titleLabel.font = [UIFont boldSystemFontOfSize:19];
asapBtn.titleLabel.textColor = [[[ConfigManager sharedInstance].skin valueForKey:@"popupButtonFontColour"] toUIColor];
[bgView addSubview:asapBtn];
} else if (selectedTableField == noPassengers)
title.text = @"Passengers";
else
title.text = @"Vehicle";
[bgView addSubview:title];
[title release];
if (version < 8)
{
[actionSheet addSubview:bgView];
}
else
{
[alertController.view addSubview:bgView];
}
[bgView release];
// travel time uses a different picker
if (selectedTableField == travelTimeText) {
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0 + bOffset, 20, 0.0, 0.0)];
[datePicker addTarget:self action:@selector(travelTimeChanged:) forControlEvents:UIControlEventValueChanged];
datePicker.datePickerMode = UIDatePickerModeDateAndTime;
datePicker.minuteInterval = 5;
if (travelTime == nil)
datePicker.date = [[NSDate date] addTimeInterval:15*60];
else
datePicker.date = travelTime;
if (version < 8)
{
[actionSheet addSubview:datePicker];
}
else
{
[alertController.view addSubview:datePicker];
}
// update table field to show now
[self travelTimeChanged:datePicker];
[datePicker release];
if (version >= 8)
{
[self presentViewController:alertController animated:NO completion:nil];
}
} else {
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0 + bOffset, 20, 0.0, 0.0)];
picker.dataSource = self;
picker.delegate = self;
if (selectedTableField == noPassengers) {
picker.showsSelectionIndicator = YES;
[picker selectRow:[passengerOptions indexOfObject:noPassengers.text] inComponent:0 animated:NO];
} else if (selectedVehicle != nil) {
[picker selectRow:[filteredCarOptions indexOfObject:selectedVehicle] inComponent:0 animated:NO];
}
if (version < 8)
{
[actionSheet addSubview:picker];
}
else
{
[alertController.view addSubview:picker];
}
[picker release];
if (version >= 8)
{
[self presentViewController:alertController animated:NO completion:nil];
}
}
} else if (selectedTableField == bookButton) {
// validate the form
[self validateForm];
}