我有一个具有3个按钮(国家,州,城市)的视图控制器(VC)。单击这些按钮后,我将显示另一个VC(使用popover segue),这是一个用于搜索国家(或州或城市)的搜索表。现在,如果用户单击两个按钮,则将同时显示两个视图控制器。我只想发表一个,怎么做?
尝试过self.view.multipleTouchEnabled = NO;但不起作用。
searchVC的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIImage *bgApplication = [UIImage imageNamed:@"bg-app-568h.jpg"];
self.view.backgroundColor = [UIColor colorWithPatternImage:bgApplication];
self.searchItems = [self loadData];
self.filteredSearchItems = [NSMutableArray arrayWithCapacity:[self.searchItems count]];
for (UIView *view in self.SearchBarBase.subviews){
if ([view isKindOfClass: [UITextField class]]) {
UITextField *tf = (UITextField *)view;
tf.delegate = self;
break;
}
}
}
- (NSArray *)loadData
{
MatchDayDataController * sharedController = [MatchDayDataController sharedDataController];
NSArray *data = [sharedController fetchStates];
//NSLog(@"states: %@", data);
return data;
}
演示者VC的代码:
-(void) viewWillAppear:(BOOL)animated
{
keyboardIsShown = NO;
MatchDayDataController *sharedController = [MatchDayDataController sharedDataController];
// Load match venue data
self.locationField.text = sharedController.matchVenue;
//Load home team related data
NSString *stateText = [sharedController.homeStateName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if ([stateText length] == 0 )
{
self.selectHomeAssoc.enabled = NO;
self.selectHomeClub.enabled = NO;
}
NSString *homeAssocText = [sharedController.homeAssociationName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if ([homeAssocText length] == 0 )
{
self.selectHomeAssoc.enabled = YES;
self.selectHomeClub.enabled = NO;
}
NSString *homeClubText = [self.homeClub.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if ([homeClubText length] == 0 )
{
self.selectHomeClub.enabled = YES;
}
self.stateTextFieldHome.text = sharedController.homeStateName;
self.homeAssociation.text = sharedController.homeAssociationName;
self.homeClub.text = sharedController.homeClubName;;
self.homeTeam.text = sharedController.homeTeamName;
// Away team related data
self.stateTextFieldAway.text = sharedController.awayStateName;
self.awayAssociation.text = sharedController.awayAssocationName;
self.awayClub.text = sharedController.awayClubName;
self.awayTeam.text = sharedController.awayTeamName;
}
- (void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
MatchDayDataController *sharedController = [MatchDayDataController sharedDataController];
sharedController.matchVenue = self.locationField.text;
// Save Venue related data
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm"];
NSString *dateTimeString = [self.dateField.text stringByAppendingString:@" "];
dateTimeString = [dateTimeString stringByAppendingString:self.timeField.text];
//NSLog(@"DateTimeString : %@", dateTimeString);
NSDate *matchDateTime = [dateFormatter dateFromString:dateTimeString];
sharedController.inspectionDate = matchDateTime;
//Save Home team related data
sharedController.homeTeamName = self.homeTeam.text;
// Save away team related data
sharedController.awayTeamName = self.awayTeam.text;
[sharedController saveData];
// hide the keyboard when we come back after leaving the cursor on text field.
// I have called resignFirstResponder on homeTeam Text field. You can use any of text field to hide.
[self.homeTeam resignFirstResponder];
[self.awayTeam resignFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated
{
[self.view endEditing:YES];
[super viewDidDisappear:animated];
}
// This event is called when the user clicks on Done/Next button in the key board.
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)segue sender:(id)sender
{
if (![sender isKindOfClass:[UIBarButtonItem class]]) {
return true;
}
return [JLTValidator validateFields:@[self.locationField, self.dateField, self.timeField, self.homeTeam, self.homeClub, self.homeAssociation, self.stateTextFieldHome, self.stateTextFieldAway, self.awayAssociation, self.awayClub, self.awayTeam]];
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//NSLog(@"segue.identifier : %@", segue.identifier);
self.popSegue = (UIStoryboardPopoverSegue *)segue;
if([segue.identifier isEqualToString:@"toSearchHomeStateFromButton"]
|| [segue.identifier isEqualToString:@"toSearchHomeStateFromText"] )
{
SearchHomeStateViewController *viewController = segue.destinationViewController;
viewController.delegate = (id) self;
}
else if ([segue.identifier isEqualToString:@"toSearchHomeAssocFromButton"] || [segue.identifier isEqualToString:@"toSearchHomeAssocFromText"])
{
HomeAssocSearchViewController *viewController = segue.destinationViewController;
viewController.delegate = (id) self;
}
else if ([segue.identifier isEqualToString:@"toSearchHomeClubFromButton"] || [segue.identifier isEqualToString:@"toSearchHomeClubFromText"])
{
SearchHomeClubViewController *viewController = segue.destinationViewController;
viewController.delegate = (id) self;
}
else if([segue.identifier isEqualToString:@"toSearchAwayStateFromButton"] || [segue.identifier isEqualToString:@"toSearchAwayStateFromText"])
{
StateViewController *viewController = segue.destinationViewController;
viewController.delegate = (id) self;
}
else if ([segue.identifier isEqualToString:@"toSearchAwayAssocFromButton"] || [segue.identifier isEqualToString:@"toSearchAwayAssocFromText"])
{
SearchAwayAssocViewController *viewController = segue.destinationViewController;
viewController.delegate = (id) self;
}
else if ([segue.identifier isEqualToString:@"toSearchAwayClubFromButton"] || [segue.identifier isEqualToString:@"toSearchAwayClubFromText"])
{
SearchAwayClubViewController *viewController = segue.destinationViewController;
viewController.delegate = (id) self;
}
}
-(void) searchHomeStateDone:(NSString *)selectedState
{
MatchDayDataController *sharedController = [MatchDayDataController sharedDataController];
sharedController.stateAwayTeam = sharedController.stateHomeTeam;
sharedController.homeTeamName = EMPTY_STRING;
sharedController.awayStateName = sharedController.homeStateName;
sharedController.awayAssocationName = EMPTY_STRING;
sharedController.awayAssociationId = EMPTY_STRING;
sharedController.awayClubName = EMPTY_STRING;
sharedController.awayClubId = EMPTY_STRING;
[self updateDataOnScreen];
self.selectHomeAssoc.enabled = YES;
self.selectHomeClub.enabled = NO;
[self.popSegue.popoverController dismissPopoverAnimated:YES];
}
-(void) searchHomeAssocDone:(NSString *)selectedHomeAssoc
{
MatchDayDataController *sharedController = [MatchDayDataController sharedDataController];
sharedController.awayAssocationName = sharedController.homeAssociationName;
sharedController.homeTeamName = EMPTY_STRING;
sharedController.awayStateName = sharedController.homeStateName;
sharedController.awayAssociationId = sharedController.homeAssociationId;
sharedController.awayClubName = EMPTY_STRING;
sharedController.awayClubId = EMPTY_STRING;
[self updateDataOnScreen];
self.selectHomeClub.enabled = YES;
[JLTValidator clearTextFieldValidation:self.homeAssociation];
[self.popSegue.popoverController dismissPopoverAnimated:YES];
}
-(void) searchHomeClubDone:(NSString *)selectedHomeClub
{
MatchDayDataController *sharedController = [MatchDayDataController sharedDataController];
sharedController.homeTeamName = EMPTY_STRING;
[self updateDataOnScreen];
[JLTValidator clearTextFieldValidation:self.homeClub];
[self.popSegue.popoverController dismissPopoverAnimated:YES];
}
-(void) searchAwayStateDone:(NSString *)selectedAwayState
{
MatchDayDataController *sharedController = [MatchDayDataController sharedDataController];
sharedController.homeTeamName = self.homeTeam.text;
[self updateDataOnScreen];
[JLTValidator clearTextFieldValidation:self.stateTextFieldAway];
[self.popSegue.popoverController dismissPopoverAnimated:YES];
}
-(void) searchAwayAssocDone:(NSString *)selectedAwayAssoc
{
MatchDayDataController *sharedController = [MatchDayDataController sharedDataController];
sharedController.homeTeamName = self.homeTeam.text;
[self updateDataOnScreen];
[JLTValidator clearTextFieldValidation:_awayAssociation];
[self.popSegue.popoverController dismissPopoverAnimated:YES];
}
-(void) searchAwayClubDone:(NSString *) selectedAwayClub;
{
MatchDayDataController *sharedController = [MatchDayDataController sharedDataController];
sharedController.homeTeamName = self.homeTeam.text;
[self updateDataOnScreen];
[JLTValidator clearTextFieldValidation:_awayClub];
[self.popSegue.popoverController dismissPopoverAnimated:YES];
}
-(void) updateDataOnScreen
{
MatchDayDataController *sharedController = [MatchDayDataController sharedDataController];
// sharedController.awayTeamName = EMPTY_STRING;
self.stateTextFieldHome.text = sharedController.homeStateName;
self.homeAssociation.text =sharedController.homeAssociationName;
self.homeClub.text = sharedController.homeClubName;
self.homeTeam.text = sharedController.homeTeamName;
self.stateTextFieldAway.text = sharedController.awayStateName;
self.awayAssociation.text = sharedController.awayAssocationName;
self.awayClub.text = sharedController.awayClubName;
//self.awayTeam.text = sharedController.awayTeamName;
}
有任何想法吗 ?
谢谢,
最佳答案
您可以创建静态布尔变量busy
,然后在每个按钮操作方法的第一行检查此变量的状态。如果busy
等于NO
,则将其设置为YES,并在最后一行操作方法中或其他位置将其设置为NO。如果busy
等于YES
,请从操作方法中返回。因此,直到第一个调用的方法没有完成,其他方法都无法运行。
@implementation yourController
-(void)changeCountry
{
if (!busy)
{
busy = YES;
// do what you need
} else return;
}
-(void)changeState
{
if (!busy)
{
busy = YES;
// do what you need
} else return;
}
@end
您应该实现单例,该单例返回具有BOOL值的静态实例,以供在差异viewControllers(1 mainC + 3 popOverC)中使用他,并在完成版本时将
busy
设置为NO
。关于ios - 禁用多点触控无法正常工作的iOS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22143166/