“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];
}
答案 0 :(得分:1)
根据您发布的代码判断,如果无法访问远程主机,则永远不会设置iLabel
的文本。因此,如果设备上没有显示标签,请在设置标签时检查设备是否可以访问远程主机。
答案 1 :(得分: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...";
}
......现在一切都好了。