我正在展示一个视图说 B 使用
[self presentViewController:vc animated:YES completion:nil];
从这个视图中,我关闭它以返回查看 A 使用
[self dismissModalViewControllerAnimated:YES];
现在,当我回去时,我想调用重新加载上一个视图(此处为视图 A)。视图 A 是具有来自服务器的数据列表的表视图。所以 reloadtable 不起作用,因为新数据只能来自服务器。所以简而言之,我想在关闭视图 B 时调用该服务器并刷新该视图。
这个怎么做。?
我曾尝试在视图 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;
}