无法更新uibutton标签

时间:2014-05-15 10:39:33

标签: ios uibutton setneedsdisplay

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

0 个答案:

没有答案