gpt4 book ai didi

ios - 单击按钮更新值

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

我是 IOS 的新手,我需要在单击按钮时显示一次,我的更新数据显示在警报 View 中。我的问题是双击按钮仅在警报 View 中更新我的数据,但 nslog 其显示方式正确,但我在按钮中失败行动。

按钮 Action 编码:

- (IBAction)buttonaction1:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Amount"
message:final
delegate:self
cancelButtonTitle:@"Book Now"
otherButtonTitles: nil];

alert.tag = 100;
[alert show];

amountstr = amountTxt.text;
NSLog(@"%@",amountstr);
str = [NSString stringWithFormat:@"type=%@&flag_id=%@&value=%@",typestr,idstr,amountstr];

[self sendDataToServer :@"POST" params:str];

}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 100)
{


if (buttonIndex == 0)
{

}else
{
// cancel button pressed
}
}
}

连接确实完成加载委托(delegate):

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{


NSError* error111;
json111 = [NSJSONSerialization JSONObjectWithData: mutableData
options:kNilOptions
error:&error111];


NSLog(@"%@",json111);
//NSDictionary *fetchDict = [json111 objectAtIndex:0];
total = [json111 objectForKey:@"Total"];
final = [NSString stringWithFormat:@"%@",total];
NSLog(@"%@",final);
}

传递 str 字符串的 Post 方法:编码:

-(void) sendDataToServer : (NSString *) method params:(NSString *)str{

NSData *postData = [str dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[str length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL]];


[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];

NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:request delegate:self];

if( theConnection ){

mutableData = [[NSMutableData alloc]init];
}
}

最佳答案

喜欢

  @interface CreateCatrgeringCustomerViewController : UIViewController<UIAlertViewDelegate>
{
NSString *currencyIDe1, *currencyIDe2, *amountType,*BranchIdes;
NSString *btnSelectType;
}

在你的 ViewDidload 上

 - (void)viewDidLoad
{
[super viewDidLoad];
// for hold the initial value do like
BranchIdes = (NSString *)[arrmsg1 objectAtIndex:0];
currencyIDe1 = (NSString *)[id1 objectAtIndex:0];
currencyIDe2 = (NSString *)[id2 objectAtIndex:0];

btnSelectType = @"no";
}
- (IBAction)buttonaction1:(id)sender {

btnSelectType = @"yes";

amountstr = amountTxt.text;
NSLog(@"%@",amountstr);
str = [NSString stringWithFormat:@"type=%@&flag_id=%@&value=%@",typestr,idstr,amountstr];

[self sendDataToServer :@"POST" params:str];

}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{


NSError* error111;
json111 = [NSJSONSerialization JSONObjectWithData: mutableData
options:kNilOptions
error:&error111];
NSLog(@"%@",json111);

if (json111)
{
if ([btnSelectType isEqualToString:@"yes"])
{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Amount"
message:final
delegate:self
cancelButtonTitle:@"Book Now"
otherButtonTitles: nil];

alert.tag = 100;
[alert show];

}

}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 100)
{

btnSelectType = @"no";

}
}

关于ios - 单击按钮更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37180777/

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