2013-07-04 3 views
1

문제가 있습니다. UITableView에서 데이터를 업데이트하는 중입니다. 나는 parseXML에서 새로운 데이터를 얻고 싶다. 서버로부터의 응답은 새로운 데이터를 UITableView로 업데이트한다. ** 아래 코드를 사용했지만 Table View에 새로운 데이터가 표시되지 않습니다. 나는 새로운 데이터를 확인하는 UpdateArray() 기능을 쓰고 당신이 나를 도와 줄 수 DIFF [Array count] 다음 내가 [tableview reloadData];데이터를 업데이트하고 UITableView에 표시하십시오.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return 1; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     return [temp count]; 

    } 

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     return 90; 
    } 



     - (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] autorelease]; 


      UILabel *FileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 30)]; 
      FileNameLabel.backgroundColor = [UIColor clearColor]; 
      FileNameLabel.font = [UIFont fontWithName:@"Helvetica" size:16]; 
      FileNameLabel.font = [UIFont boldSystemFontOfSize:16]; 
      FileNameLabel.textColor = [UIColor blackColor]; 
      NSLog(@"Reseversed TEMP array %@",temp); 
      FileNameLabel.text =[temp objectAtIndex:indexPath.row]; 
      [cell.contentView addSubview: FileNameLabel]; 
      [FileNameLabel release]; 

      UILabel *UploadTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 25)]; 

      UploadTimeLabel.backgroundColor = [UIColor clearColor]; 
      UploadTimeLabel.font = [UIFont fontWithName:@"Helvetica" size:14]; 
      UploadTimeLabel.textColor = [UIColor grayColor]; 
      UploadTimeLabel.text = [UploadTimeArray objectAtIndex:indexPath.row]; 
      [cell.contentView addSubview: UploadTimeLabel]; 
      [UploadTimeLabel release]; 

      UILabel *CompleteLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 12, 170, 25)]; 
      CompleteLabel.backgroundColor = [UIColor clearColor]; 
      CompleteLabel.font = [UIFont fontWithName:@"Helvetica" size:14]; 
      CompleteLabel.textColor = [UIColor darkGrayColor]; 
      CompleteLabel.text [email protected]"Completed"; 
      CompleteLabel.textAlignment = NSTextAlignmentRight; 
      [cell.contentView addSubview: CompleteLabel]; 
      [CompleteLabel release]; 
     } 
      return cell; 
    } 

UpdateArray()

-(void)updateArray{ 

    while (loop) 
    { 
     [NSThread sleepForTimeInterval:4.0]; 

     [FileCompletedArray removeAllObjects]; 
    // [temp removeAllObjects]; 
     .... 
     AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest]; 

     [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 
      NSLog(@"Success"); 
      NSString * parsexmlinput = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; 
      NSLog(@"Response in Loop CompleteView: %@", parsexmlinput); 
      // dispatch_async(dispatch_get_main_queue(), ^{ 
       [self parseXMLFile:parsexmlinput]; 

      NSLog(@"File Completed array: %@", FileCompletedArray); 
      NSLog(@"File Temp out array: %@", temp); 
      NSLog(@"File Completed count: %lu",(unsigned long)[ FileCompletedArray count]); 
      NSLog(@"File Temp out count: %lu", (unsigned long)[temp count]); 
      // NSLog(@"State: %@", state); 

      if([FileCompletedArray count ] != [temp count]) 
      { 
       [temp removeAllObjects]; 
       temp= [FileCompletedArray mutableCopy]; 
       [_tableView reloadData]; 
      } 
      else 
      { 
       NSLog(@"2 array equal"); 
      } 
    //}); 
     } 
     failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
               NSLog(@"error: %@", error); 

              } 
     ]; 
     [httpClient enqueueHTTPRequestOperation:operation]; 
    } 
} 

를 호출하는 경우 다음 나는,이 배열을 비교? 미리 감사드립니다.

+0

if 조건은 YES를 반환하고 영역으로 들어가고 reloadData? 이것 이후에 행 수가 호출되고 임시 값이 맞습니까? 어쩌면 정적 NSString * CellIdentifier = @ "Cell"; 뒤에 중단 점을 설정할 수 있습니다 – geo

+0

2 배열을 비교할 때 항상 서버에 새 데이터가 있지만 같음. 내가 뭘 잘못 했니? – NGOT

+0

다른 문제를 조사해야합니다. 어쩌면'[self parseXMLFile : parsexmlinput];을 확인해 보라. 또한 NSLog (@ "File Completed array : % @", FileCompletedArray)의 내용; NSLog (@ "File Temp out array : % @", temp);'좋은 정보 일 수 있습니다. 새 행이 이동 중이거나 데이터가 업데이트 된 경우에만 업데이트하고 싶습니까? 좋은 이름으로 변수를 명명하는 것은 나쁜 습관입니다.) – geo

답변

1

나는 당신이 reloadData를 호출하는 것을 보았다.

EDIT :

당신은

1 온도가 [임시 카운트] 제로 복귀되지 않는다는 것을 의미 나 개체를 갖는 것을 확인한다.

2 두 배열을 검사하는 if 조건이 트리거됩니다. 다시로드 데이터가 호출됨을 의미합니다.

3 - cell.contetview addsubview 다음에 중단 점을 만들 수 있으며 셀에 현재 들어있는 내용을 확인할 수 있습니까?

+0

감사합니다. 코드를 업데이트했습니다. – NGOT

+0

지금 작동합니까? –

+0

아니, 작동하지 않습니다. 나는 이유를 모른다. – NGOT

0

당신은

[_tableView reloadRowsAtIndexPaths:[_tableView indexPathsForVisibleRows] 
           withRowAnimation:UITableViewRowAnimationNone]; 

당신이 테이블보기를 새로 고치면 다음이 줄을 & 확인하려고

[_tableView beginUpdates]; 
... 
[_tableView endUpdates]; 

전화를 걸거나

[_tableView reloadData]; 
+0

[_tableView reloadData]를 호출했습니다. 하지만 그것은 tableView를 다시로드하지 않습니다. 감사. 다른 제안이 있으십니까? – NGOT

0

전화를해야 호출하기 전에 :

mytableview는 tableview의 obj이며 여기서 tableview 객체를 제공합니다.

관련 문제