문제가 있습니다. 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];
}
}
를 호출하는 경우 다음 나는,이 배열을 비교? 미리 감사드립니다.
if 조건은 YES를 반환하고 영역으로 들어가고 reloadData? 이것 이후에 행 수가 호출되고 임시 값이 맞습니까? 어쩌면 정적 NSString * CellIdentifier = @ "Cell"; 뒤에 중단 점을 설정할 수 있습니다 – geo
2 배열을 비교할 때 항상 서버에 새 데이터가 있지만 같음. 내가 뭘 잘못 했니? – NGOT
다른 문제를 조사해야합니다. 어쩌면'[self parseXMLFile : parsexmlinput];을 확인해 보라. 또한 NSLog (@ "File Completed array : % @", FileCompletedArray)의 내용; NSLog (@ "File Temp out array : % @", temp);'좋은 정보 일 수 있습니다. 새 행이 이동 중이거나 데이터가 업데이트 된 경우에만 업데이트하고 싶습니까? 좋은 이름으로 변수를 명명하는 것은 나쁜 습관입니다.) – geo