gpt4 book ai didi

ios - 禁用多点触控不工作 ios

转载 作者:行者123 更新时间:2023-11-29 03:12:08 26 4
gpt4 key购买 nike

我有一个 View Controller (VC),有 3 个按钮(国家、州、城市)。单击这些按钮后,我将呈现另一个 VC(使用弹出框转场),这是一个用于搜索国家(或州或城市)的搜索表。现在,如果用户单击两个按钮,则两个 View Controller 都会同时呈现。我只想展示一份。该怎么做?

尝试过 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;
}

有什么想法吗?

谢谢

最佳答案

您可以创建静态 bool 变量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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com