gpt4 book ai didi

ios - Xcode - 通过 segue 推送 View 的问题

转载 作者:行者123 更新时间:2023-11-29 01:48:11 25 4
gpt4 key购买 nike

我想使用推送转场来更改 View 。另外,我想将一些数据过去到目标 View 。在 segue 更改 View 之前,我想弹出一个带有文本字段的警报 View 来检查用户密码。如果匹配,它将改变 View 。如果没有,它将停止推送转场。

我知道如果要阻止push segue做某事首先需要使用下面的方法,但是它无法获取segue.destinationViewController。无论如何可以替换 segue.destinationViewController 吗?

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender

此外,我能否在 - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender 方法中获取 alertView 文本字段结果?

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
if ([identifier isEqualToString:@"chatSegue"]) {
NSLog(@"should");
NSString *plock = [Server getUserDatawithkey:@"plock"];
if ([plock isEqual:@"1"]) {

UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Privacy Lock" message:@"Please enter your password:" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * addFriendField = [alert textFieldAtIndex:0];
addFriendField.keyboardType = UIKeyboardTypeDefault;
addFriendField.placeholder = @"Enter your password";
alert.tag = ALERT_TAG_PW;
[alert show];
// Can I get the alertView textfield result at here?

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
friendCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

// Is anyway to replace the segue.destinationViewController?
chatViewController *cvc = segue.destinationViewController;
cvc.fid = cell.fid.text;
cvc.title = cell.f_name.text;
return YES;
}
return NO;
}
return YES;
}

有人可以帮助我吗?谢谢!

最佳答案

与其在 shouldPerformSegueWithIdentifier 中创建警报,不如在其他地方(调用推送的任何地方)创建它,并根据该警报的结果操作执行 [self performSegueWithIdentifier:@"yourIdentifier "发件人:自己];

要处理警报的结果,您需要使用 UIAlertViewDelegate 和方法 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex .

可能看起来像这样......

- (void)getServerStuff {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Privacy Lock" message:@"Please enter your password:" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * addFriendField = [alert textFieldAtIndex:0];
addFriendField.keyboardType = UIKeyboardTypeDefault;
addFriendField.placeholder = @"Enter your password";
alert.tag = ALERT_TAG_PW;
[alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag == ALERT_TAG_PW) {
if(buttonIndex == 0) {
[self performSegueWithIdentifier:@"pushViewIdentifier" sender:self];
}
else if (buttonIndex == 1) {
//Do Nothing
}
}
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"pushViewIdentifier" sender:self]) {
ChatViewController *cvc = (ChatViewController *)segue.destinationViewController;
cvc.property = self.someProperty;
}
}

关于ios - Xcode - 通过 segue 推送 View 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31686077/

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