-1

“iLabel”在模拟器中显示,但一旦归档并运行 IPA 文件,它就无法显示。我尝试清理代码,但没有做任何事情。iLabel 的想法是在 UIIndicator 动画时显示,当然当指示器消失时也会消失。

- (void)viewDidLoad
{
  [super viewDidLoad];

  [[self myTableView] setDelegate:self];
  [[self myTableView] setDataSource:self];
  array = [[NSMutableArray alloc] init];

  [self startActivity];
}

-(void)startActivity
{
  indicator.hidden=NO;
  [indicator startAnimating];

  [self uploadData];
  NSLog(@"VIEWDIDLOAD-INDICATOR-TURNING-ON: %@", indicator);
}

-(void)uploadData
{
  NSLog(@"Uploading...");

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkForReachability) name:kReachabilityChangedNotification object:nil];

  Reachability *reachability = [Reachability reachabilityForInternetConnection];
  [reachability startNotifier];

  NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];

  if(remoteHostStatus == NotReachable)
  {
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"Oops..."
                          message: @"Network connection lost."
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [alert show];    }

  else if (remoteHostStatus == ReachableViaWiFi)
  {
    iLabel.text = @"Please be patient...";
  }
}


- (void) connectionDidFinishLoading:(NSURLConnection *)connection
{
  [self setString];

  NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
  NSString *string1 = [dic objectForKey:@"name"];
  NSString *string7 = [dic objectForKey:@"review_count"];
  NSString *string3 = [dic objectForKey:@"display_phone"];
  NSDictionary *location = [dic objectForKey:@"location"];
  NSArray *array2 = [location objectForKey:@"display_address"];
  NSDictionary *coordinate = [location objectForKey:@"coordinate"];

  lat = [coordinate objectForKey:@"latitude"];
  lon = [coordinate objectForKey:@"longitude"];
  mURL = [dic objectForKey:@"mobile_url"];

  NSString *string4 = [array2 objectAtIndex:0];
  NSString *string5 = [array2 objectAtIndex:1];
  NSString *img2String = [dic objectForKey:@"image_url"];

for (NSDictionary *diction in dic)
{
    NSString *string6 = [NSString stringWithFormat:@"Yelp Rating:                   "];
    NSString *string8 = [NSString stringWithFormat:@"Based on %@ Review(s)", string7];

    [array addObject:string1];
    [array addObject:string6];
    [array addObject:string8];
    [array addObject:string3];
    [array addObject:string4];
    [array addObject:string5];

    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:img2String]]];
    imageView.image = image;
  }

  for (NSDictionary *diction in coordinate)
  {
    [array addObject:lat];
    [array addObject:lon];
  }

  [[self myTableView] reloadData];

  [indicator stopAnimating];
  indicator.hidden=YES;
  [indicator removeFromSuperview];

  iLabel.text = @"";
  [iLabel removeFromSuperview];
}
4

2 回答 2

1

从您发布的代码来看,如果无法访问远程主机,则您永远不会设置iLabel. 因此,如果标签未显示在设备上,请在设置标签时检查远程主机是否可以从设备访问。

于 2013-02-27T03:01:59.850 回答
0

不知道为什么我没有早点抓住它。问题如下:

    if(remoteHostStatus == NotReachable)
    {
      UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"Oops..."
                          message: @"Network connection lost."
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
      [alert show];    }

    else if (remoteHostStatus == ReachableViaWiFi)
    {
      ilabel.text = @"Please be patient...";
    }

我将底部更改为:

    else
    {
      ilabel.text = @"Please be patient...";
    }

...现在一切都很好。

于 2013-02-27T04:03:17.610 回答