当我输入此viewController
时,我正在调用此loadView
方法。之后,我在getStatus
viewDidLoad
-(void)loadView
{
CGRect frame = [UIScreen mainScreen].bounds;
self.view = [[UIView alloc] init];
self.view.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
self.view.backgroundColor = [UIColor colorWithRed:19.0/255.0 green:155.0/255.0 blue:235.0/255.0 alpha:1];
footerView = [[UIView alloc] init];
footerView.frame = CGRectMake(0, frame.size.height-60, screenwidth, 60);
[footerView setBackgroundColor:[UIColor colorWithRed:19.0/255.0 green:155.0/255.0 blue:235.0/255.0 alpha:1]];
[self.view addSubview:footerView];
deleteBotl = [UIButton buttonWithType:UIButtonTypeCustom] ;
[deleteBotl setImage:[UIImage imageNamed:@"delete_botl.png"] forState:UIControlStateNormal];
deleteBotl.frame =CGRectMake(screenwidth/2+115,footerView.frame.size.height/2-20, 40, 40);
deleteBotl.showsTouchWhenHighlighted = YES;
[footerView addSubview:deleteBotl];
[deleteBotl addTarget:self action:@selector(deleteBotl) forControlEvents:UIControlEventTouchDown];
reportBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
[reportBtn setImage:[UIImage imageNamed:@"report_botl.png"] forState:UIControlStateNormal];
reportBtn.frame = CGRectMake(screenwidth/2+115,footerView.frame.size.height/2-20, 40, 40);
reportBtn.showsTouchWhenHighlighted = YES;
[footerView addSubview:reportBtn];
[reportBtn addTarget:self action:@selector(reportWithDefaultAlert) forControlEvents:UIControlEventTouchDown];
removeBotl = [UIButton buttonWithType:UIButtonTypeCustom] ;
[removeBotl setImage:[UIImage imageNamed:@"remove_botl.png"] forState:UIControlStateNormal];
removeBotl.frame = CGRectMake(screenwidth/2+115,footerView.frame.size.height/2-20, 40, 40);
removeBotl.showsTouchWhenHighlighted = YES;
[footerView addSubview:removeBotl];
[removeBotl addTarget:self action:@selector(removeBotl) forControlEvents:UIControlEventTouchDown];
}
我在viewDidLoad
中调用的此方法此getStatus
函数正在调用服务并获取响应。基于该响应,我正在进行隐藏并取消隐藏buttons
。隐藏和取消隐藏是可行的,但隐藏和取消隐藏需要很长时间。我很快得到了答复。但这需要很长时间。
-(void) getStatus
{
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
NSString *userid = [userDefault objectForKey:kUserId];
float latitude = locationManager.location.coordinate.latitude;
float longitude = locationManager.location.coordinate.longitude;
Utils *util = [[Utils alloc]init];
NSString *ipaddress = [util getIPAddress];
NSString *urlString = [NSString stringWithFormat:@"%@%@%f%@%f%@%@%@%@%@%@", kBOTL_URL_1, @"/postlanglat?lat=",latitude, @"&lang=",longitude, @"&bid=",[self.Botl stringForKey:@"bid"],@"&uid=",userid,@"&ip=",ipaddress];
NSLog(@"My URL--->. %@", urlString);
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:urlString ]]];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[NSURLConnection sendAsynchronousRequest: request
queue: queue
completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error) {
if (error || !data)
{
NSLog(@"Dict--->.error");
}
else
{
NSLog(@"Server Response :%@",response);
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Server Srting Bottom Button :%@",responseString);
NSDictionary *dict = [responseString JSONValue];
NSLog(@"Dict---> %@", dict); // i am getting the respose here while loading the viewcontroller
NSString *liked = dict[@"like"];
NSString *userId = [[NSUserDefaults standardUserDefaults] valueForKey:kUserId];
NSString *botlUserId = [NSString stringWithFormat:@"%@", self.Botl[@"botlUser_id"]];
NSLog(@"userId-----------------------%@",userId);
NSLog(@"botlUserId-----------------------%@",botlUserId);
NSLog(@"rebotlUserId-----------------------%@",self.rebotled);
// amd also getting the above values as at the begining
if([userId isEqualToString:botlUserId])
{
deleteBotl.hidden = NO;
reportBtn.hidden = YES;
removeBotl.hidden = YES;
}
else if([self.rebotled boolValue]==true)
{
deleteBotl.hidden = YES;
reportBtn.hidden =YES;
removeBotl.hidden = NO;
}
else
{
deleteBotl.hidden = YES;
reportBtn.hidden = NO;
removeBotl.hidden = YES;
}