我正在使用自定义MZFormSheetController
来使用自定义“警报视图”。当我按下它时,我有一个按钮,它会打开MZFormSheetController
并允许我从 中选择此按钮的特定标题UIPickerView
。当我从选择器中选择标题时,它被发送到viewController
包含按钮的setNeedsDisplay
我想用从pickerView
. 我写了代码,但按钮的标题没有更新..
在按钮的viewController
, 按钮的动作:
-(IBAction)openSelectCountries:(id)sender{
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"countriesPickerViewController"];
MZFormSheetController *formSheet = [[MZFormSheetController alloc] initWithViewController:vc];
formSheet.transitionStyle = MZFormSheetTransitionStyleSlideFromTop;
formSheet.shadowRadius = 2.0;
formSheet.shadowOpacity = 0.3;
formSheet.shouldDismissOnBackgroundViewTap = YES;
formSheet.shouldCenterVerticallyWhenKeyboardAppears = YES;
[formSheet presentAnimated:YES completionHandler:^(UIViewController *presentedFSViewController) {
}];
}
在viewDidLoad
:
// selectedCountryIndex2 is a static NSString
if (selectedCountryIndex != 0) {
selectedCountryIndex2 = selectedCountryIndex;
}
NSLog(@"selectedCountryIndex2: %d", selectedCountryIndex2);
if (selectedCountryIndex2 == 0) {
NSLog(@"no country selected");
}else{
NSLog(@"the selected country: %@", [countryArray objectAtIndex:selectedCountryIndex2]);
[countrySelect setTitle:[countryArray objectAtIndex:selectedCountryIndex2] forState: UIControlStateNormal];
}
在CountriesPickerViewController.m
:
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [countryArray count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [countryArray objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@"in pickerView: %@", [countryArray objectAtIndex:row]);
ContactUsViewController *contactUsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contactUsViewController"];
contactUsViewController.selectedCountry = [countryArray objectAtIndex:row];
contactUsViewController.selectedCountryIndex = row;
[contactUsViewController.view setNeedsDisplay];
// to close the custom dialog
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"countriesPickerViewController"];
MZFormSheetController *formSheet = [[MZFormSheetController alloc] initWithViewController:vc];
[formSheet dismissFormSheetControllerAnimated:YES completionHandler:nil];
}
预期的事情是countrySelect
按钮在selectedCountryIndex2
不等于 0 时更改其标题,但这从未发生过,尽管标题已成功传递并且我得到了它NSLog
。