gpt4 book ai didi

iphone - 使用dismissModalViewControllerAnimated刷新上一个 View

转载 作者:行者123 更新时间:2023-12-01 17:41:21 24 4
gpt4 key购买 nike

我正在展示一个 View 说 B 使用

 [self presentViewController:vc animated:YES completion:nil];

从这个 View 中,我关闭它以返回查看 A 使用
  [self dismissModalViewControllerAnimated:YES];

现在,当我回去时,我想调用重新加载上一个 View (此处为 View A)。 View A 是具有来自服务器的数据列表的 TableView 。所以 reloadtable 不起作用,因为新数据只能来自服务器。所以简而言之,我想在关闭 View B 时调用该服务器并刷新该 View 。

这该怎么做。?

我曾尝试在 View A 的 ViewWillAppear 方法中调用 ViewDidLoad,但没有成功。

请在这方面提供帮助。

编辑 :
我的服务器调用是这样的
 - (void)viewWillAppear:(BOOL)animated
{
NSString *path = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"path"];

NSString *address = [NSString stringWithFormat:@"%@%@%d%@%@", path,@"questions/?cat=",self.category,@"&que_language=",language];

NSString* encodedUrl = [address stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];

NSURL *URL = [NSURL URLWithString:encodedUrl];
NSLog(@"%@",address);

[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[URL host]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL cachePolicy:NSURLCacheStorageAllowedInMemoryOnly
timeoutInterval:60.0];

[request setHTTPMethod:@"GET"];

responseData = [[NSMutableData alloc] init];

// [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
//Write code you want to call when data is received,

NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

if (data) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
int statuscode = [httpResponse statusCode];
NSString *responseMsg = [NSHTTPURLResponse localizedStringForStatusCode:statuscode];
switch (statuscode) {
case 200:{
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"data:%@",responseString);

SBJsonParser *parser = [[SBJsonParser alloc] init];
NSMutableArray *object = [parser objectWithString:responseString error:nil];

questionList = [[NSMutableDictionary alloc] init ];
questions = [[NSMutableDictionary alloc] init ];
que_id = [[NSMutableDictionary alloc] init ];
ans_count = [[NSMutableDictionary alloc] init ];

int i=0;

for (NSDictionary *quelist in object) {

NSString *que = [quelist objectForKey:@"que_content"];
NSString *queId = [NSString stringWithFormat:@"%@",[quelist objectForKey:@"question_id"]] ;
NSString *ansCount = [NSString stringWithFormat:@"%@",[quelist objectForKey:@"ans_count"]] ;

[self.questions setValue:que forKey:[NSString stringWithFormat:@"%d",i]];
[self.que_id setValue:queId forKey:[NSString stringWithFormat:@"%d",i]];
[self.ans_count setValue:ansCount forKey:[NSString stringWithFormat:@"%d",i]];

[self.questionList setValue:que forKey:queId];

i++;
}
break;
}
}
[self.table reloadData];
[self.table reloadInputViews];
}
}

编辑 2:
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

int rowNumber = indexPath.row;

cell.textLabel.text = [questions valueForKey:[NSString stringWithFormat:@"%d",rowNumber]];

NSString *ansCount = [ans_count valueForKey:[NSString stringWithFormat:@"%d",rowNumber]];

UILabel *ans = [[UILabel alloc] initWithFrame:CGRectMake(15,39,100,12)];
ans.text = [NSString stringWithFormat:@"%@%@%@",ansCount,@" ",@"Answers"];
ans.font = [UIFont fontWithName:@"Arial" size:12.0f] ;
ans.textColor = [UIColor blueColor];
[cell.contentView addSubview:ans];

UIButton *showbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
showbtn.frame = CGRectMake(280, 10, 21, 21);
showbtn.tag = rowNumber;

[showbtn setBackgroundImage:[UIImage imageNamed:@"right.png"] forState:UIControlStateNormal];
[showbtn addTarget:self action:@selector(showDetailedQuestion:) forControlEvents:UIControlEventTouchUpInside];

[cell.contentView addSubview:showbtn];
}

// All bgColor configuration moves here

cell.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor grayColor];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16.0f] ;


return cell;
}

最佳答案

你有几个选择:

  • 如果是iPhone专用或者全屏呈现,可以等待viewDidAppear被称为。
  • 您可以实现 refresh调用 A,然后调用 B,调用 viewDidDisappear ,你可以看看B的presentingViewController respondsToSelector:@selector(refresh) ,如果是,请调用 refreshpresentingViewController .
  • 您可以从 B 发布一些通知并从 A 收听。
  • 关于iphone - 使用dismissModalViewControllerAnimated刷新上一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18649846/

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