我是新的客观的C语言我试图在目标c上设置Tableviewcell的进度条,但进度条不更新

在这里input图像描述

我想更新这个进度条,根据数据来自服务器

1)从asynchronous数据更新进度条2)并将video上传到服务器

#import "NotificationsViewController.h" #import "NotificationsListTableViewCell.h" #import "HeaderNotificationTableViewCell.h" #import "NotificationsWebservice.h" #import "UserDetails.h" #import "LoaderView.h" #import "VideoResponseQuestionViewController.h" #import "VideoResponseOnboardingViewController.h" #import "RegistrationWebservice.h" #import "URLS.h" #import <AFNetworking/UIKit+AFNetworking.h> @interface NotificationsViewController () { LoaderView *loaderView; NSMutableArray *interactionsArray; NSMutableArray *generalArray; NSString *objectId; NSIndexPath *indexPath; NSData* data; NSOperation *operationTask; int count; NSString *lastIndexPath; BOOL isSelectedRow; } @property (weak, nonatomic) IBOutlet UITableView *notificationTableView; @property (nonatomic) NSString *playingFilename; @property (nonatomic,strong) NSURLConnection *getReportConnection; @property (retain, nonatomic) NSData *receivedData; @property (nonatomic,strong) NSMutableArray *reportArray; @end @implementation NotificationsViewController - (void)viewDidLoad { [super viewDidLoad]; _unreadBackground.layer.cornerRadius = 3.0f; [_unreadBackground setClipsToBounds:YES]; [self setUpCell]; } -(void)viewWillAppear:(BOOL)animated { [self GetNotificationsList]; self.navigationController.navigationBar.hidden = NO; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; } 

从VideoViewController获取数据

  -(void)passValue:(NSURL*)getValue { NSLog(@"Value is %@",getValue); // I am Getting Value Here _storeValue = getValue; if(_storeValue == nil){ NSLog(@"Nil Data "); } } -(void)passQuestion:(NSString *)getQuestion { NSLog(@"Value is %@",getQuestion); // I am Getting Value Here _storeQuestion = getQuestion; if(_storeQuestion == nil){ NSLog(@"Nil Data "); }else{ [self UpdateUserProfileImage]; } } 

#pragma mark – SetUp cell – (void)setUpCell {

  interactionsArray = [[NSMutableArray alloc] init]; generalArray = [[NSMutableArray alloc] init]; _notificationTableView.estimatedRowHeight = 349; _notificationTableView.rowHeight = UITableViewAutomaticDimension; UINib *cellNib1 = [UINib nibWithNibName:NSStringFromClass([HeaderNotificationTableViewCell class]) bundle:nil]; [_notificationTableView registerNib:cellNib1 forCellReuseIdentifier:@"HeaderNotificationTableViewCell"]; UINib *cellNib2 = [UINib nibWithNibName:NSStringFromClass([NotificationsListTableViewCell class]) bundle:nil]; [_notificationTableView registerNib:cellNib2 forCellReuseIdentifier:@"NotificationsListTableViewCell"]; } 

#pragma标记 – UItableview数据源和Delgate

  -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return generalArray.count+1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row == 0) { HeaderNotificationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HeaderNotificationTableViewCell"]; cell.myLabel.text = @""; return cell; }else { NotificationsListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NotificationsListTableViewCell"]; if ([[NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"notificationType"]] isEqualToString:@"Game"]) { cell.nameTitleLabel.text = [NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"notificationType"]]; cell.subTitleLabel.text = [NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"message"]]; cell.logoImageView.image = [UIImage imageNamed:@"noun_869979_cc"]; cell.recordImageView.alpha = 0; cell.progressbar.alpha = 0; cell.percentageLabel.alpha = 0; } else if ([[NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"notificationType"]] isEqualToString:@"Video Response"]) { cell.nameTitleLabel.text = [NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"notificationType"]]; cell.subTitleLabel.text = [NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"message"]]; cell.logoImageView.image = [UIImage imageNamed:@"noun_1094110_cc"]; cell.recordImageView.alpha = 1; lastIndexPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"lastIndexPathUsed"]; NSString *indexROwSelected = lastIndexPath; NSInteger selectedIndex = [indexROwSelected integerValue]; if(indexPath.row == selectedIndex){ NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults]; [userdefaults removeObjectForKey:@"lastIndexPathUsed"]; [userdefaults synchronize]; lastIndexPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"lastIndexPathUsed"]; cell.progressbar.alpha = 1; cell.percentageLabel.alpha = 1; cell.recordImageView.image = [UIImage imageNamed:@"correctAnswer"]; cell.progressbar.progress = count; cell.percentageLabel.text = [NSString stringWithFormat:@"%d %%",count]; }else{ cell.progressbar.alpha = 0; cell.percentageLabel.alpha = 0; } if([[NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"status"]] isEqualToString:@"Notified"]){ cell.recordImageView.image = [UIImage imageNamed:@"correctAnswer"]; }else if([[NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"status"]] isEqualToString:@"Pending"]){ cell.recordImageView.image = [UIImage imageNamed:@"Red dot"]; } } NSString *dateString = [NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"createdAt"]]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd:HH:mm"]; NSDate *date = [dateFormatter dateFromString:dateString]; cell.layer.shadowColor = [[UIColor blackColor] CGColor]; cell.layer.shadowOffset = CGSizeMake(1.0f, 1.0f); cell.layer.shadowRadius = 2.0f; cell.layer.shadowOpacity = 1.0f; return cell; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([[NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"notificationType"]] isEqualToString:@"Game"]) { [self.tabBarController setSelectedIndex:1]; } if ([[NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"notificationType"]] isEqualToString:@"Learning"]) { [self.tabBarController setSelectedIndex:2]; } if ([[NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"notificationType"]] isEqualToString:@"Video Response"]) { objectId = [NSString stringWithFormat:@"%@",generalArray[indexPath.row-1][@"objectId"]]; [self performSegueWithIdentifier:@"VideoResponseIdentifier" sender:self]; NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults]; [userdefaults setObject:[NSString stringWithFormat:@"%d",indexPath.row] forKey:@"lastIndexPathUsed"]; } } 

编译指示检查推送通知列表

  -(void)GetNotificationsList { [interactionsArray removeAllObjects]; [generalArray removeAllObjects]; [self.notificationTableView reloadData]; NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; [params setValue:[[UserDetails classMethodeOfUserDetails] getUserId] forKey:@"id"]; NSLog(@"Params %@",params); [[NotificationsWebservice sharedService] getNotificationsWithParams:params Completion:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { dispatch_async(dispatch_get_main_queue(), ^{ [self removeLoader]; }); }else{ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSLog(@"response status code: %ld", (long)[httpResponse statusCode]); dispatch_async(dispatch_get_main_queue(), ^{ // code here NSDictionary *jsonLoginDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSLog(@"Data %@",jsonLoginDictionary); dispatch_async(dispatch_get_main_queue(), ^{ if ([httpResponse statusCode] == 200) { NSArray *myArray = [jsonLoginDictionary objectForKey:@"notificationList"]; NSLog(@"%@",myArray); for (int i=0; i<myArray.count; i++) { if ([myArray[i] isKindOfClass:[NSDictionary class]]) { if ( [[NSString stringWithFormat:@"%@",myArray[i][@"status"]] isEqualToString:@"Pending"]) { [interactionsArray addObject:myArray[i]]; NSLog(@"Count: %lu", (unsigned long)[interactionsArray count]); } [generalArray addObject:myArray[i]]; } } [self.notificationTableView reloadData]; [self removeLoader]; } else { [self removeLoader]; } }); }); } }]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0){ return 0; } else{ return 100; } } -(void)removeLoader{ [loaderView removeFromSuperview]; } 

编译指令使用标识符方法

  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"VideoResponseIdentifier"]) { // Get destination view VideoResponseOnboardingViewController *vc = [segue destinationViewController]; vc.videoID = objectId; } } 

发送数据到服务器

  -(void)UpdateUserProfileImage { NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; // getting an NSString NSString *videoID = [prefs stringForKey:@"SaveVideoId"]; NSData* data = [NSData dataWithContentsOfURL:_storeValue]; NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; [params setValue:videoID forKey:@"id"]; [params setValue:_storeQuestion forKey:@"question"]; [self updateUserVideoResponse:params ImageFile:data Completion:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { dispatch_async(dispatch_get_main_queue(), ^{ if(error){ [self NoInternetConnection]; }else{ } }); } else { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSLog(@"response status code: %ld", (long)[httpResponse statusCode]); NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSLog(@"Data %@",jsonDictionary); if ([httpResponse statusCode]==200) { NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSLog(@"Data %@",jsonDictionary); } else { dispatch_async(dispatch_get_main_queue(), ^{ [self NoInternetConnection]; // [self removeLoader]; }); } } }]; } #upload DAta to Server with Asynchronous method -(void)updateUserVideoResponse:(NSMutableDictionary*)params ImageFile:(NSData*)Img Completion:(void (^)(NSData *data, NSURLResponse *response, NSError *error))callback{ NSLog(@"Params %@",params); NSURL *myURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",VideoAddResponseUrl,[params objectForKey:@"id"]]]; NSLog(@"%.2f",(float)Img.length); NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; [request setHTTPShouldHandleCookies:NO]; [request setTimeoutInterval:60]; [request setURL:myURL]; [request setHTTPMethod:@"PUT"]; NSString *boundary = @"_187934598797439873422234"; // set Content-Type in HTTP header NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; [request setValue:contentType forHTTPHeaderField: @"Content-Type"]; // post body NSMutableData *body = [NSMutableData data]; // add params (all params are strings) [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=%@\r\n\r\n", @"imageCaption"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"%@\r\n", @"Some Caption"] dataUsingEncoding:NSUTF8StringEncoding]]; // add image data // if (imageData) { [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=%@; filename=imageName.jpg\r\n", @"imageFormKey"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[NSData dataWithData:Img]]; [body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; // } [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; // setting the body of the post to the reqeust [request setHTTPBody:body]; // set the content-length NSString *postLength = [NSString stringWithFormat:@"%d", [body length]]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 

请检查这是Asynchronousrequest它没有更新到进度条

  [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { NotificationsListTableViewCell *cell = (NotificationsListTableViewCell*)[self tableView:self.notificationTableView cellForRowAtIndexPath:indexPath]; int progressvalue = (*(int*)([data bytes])); count = progressvalue/progressvalue; cell.progressbar.progress = count/100; cell.percentageLabel.text = [NSString stringWithFormat:@"%d %%",count]; [self.notificationTableView reloadData]; }]; } #InternetConnection is Available or not -(void)NoInternetConnection{ NSString *message = @"Please Check Internet Connection And Network Issue!"; UIAlertView *toast = [[UIAlertView alloc] initWithTitle:@"Alert" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"RETRY", nil]; [toast show]; [toast cancelButtonIndex]; [toast firstOtherButtonIndex]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == 1) { [self setUpCell]; } else { // be nice with the world, maybe initiate some Ecological action as a bonus } }