1

を使用してBと言うビューを提示しています

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

そして、このビューから私はそれを閉じてビューAに戻ります

  [self dismissModalViewControllerAnimated:YES];

今戻ったら、前のビューのリロードを呼び出したいです(ここではビューA)。ビューAは、サーバーからのデータのリストを持つテーブルビューです。したがって、新しいデータはサーバーからのみ取得できるため、reloadtable は機能しません。要するに、ビューBを閉じながら、そのサーバーを呼び出してそのビューを更新したい.

これを行う方法。?

ビュー A の ViewWillAppear メソッドで ViewDidLoad を呼び出してみましたが、うまくいきませんでした。

これを手伝ってください。

EDIT:私のサーバーコールはこのようなものです

 - (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;
}
4

3 に答える 3

2

次の方法を使用します。

[self dismissViewControllerAnimated:YES completion:^{
                    //Reload the table view here
                }];

(使用している方法は非推奨です。)

于 2013-09-06T04:31:00.007 に答える
1

viewDidLoad で webservice を呼び出さないでください。それには viewWillAppear を使用してください。ビューが表示されるたびに呼び出され、問題が解消されます。

あなたの編集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;
}
于 2013-09-06T04:36:32.510 に答える