我使用自定义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
得到了它。