0
NSOperation에 문제가 있습니다. 여러 방법을 시도했지만 화면 뒤에서 실행되지만 내 테이블보기에는 나타나지 않습니다. 아무도 나를 도와 줄 수 없어. 나는 NSOperation을 처음 사용합니다.NSOperation이 TableView에 데이터를로드 할 수 없습니다.
Recents.h
#import "Recents.h"
#import "PersonList.h"
#import "PhotoDetail.h"
@implementation Recents
@synthesize picName,picture,name,names,pics,lists,namelists;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
[email protected]"Recents";
}
return self;
}
- (void)beginLoadingFlickrData{
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(synchronousLoadFlickrData) object:nil];
[operationQueue addOperation:operation];
[operation release];
}
- (void)synchronousLoadFlickrData{
fetcher=[FlickrFetcher sharedInstance];
NSArray *recents=[fetcher recentGeoTaggedPhotos];
[self performSelectorOnMainThread:@selector(didFinishLoadingFlickrDataWithResults:) withObject:recents waitUntilDone:NO];
}
- (void)didFinishLoadingFlickrDataWithResults:(NSArray *)recents{
for(NSDictionary *dic in recents){
[names addObject:[fetcher usernameForUserID:[dic objectForKey:@"owner"]]];
if([[dic objectForKey:@"title"]isEqualToString:@""]){
[pics addObject:@"Untitled"];
}else{
[pics addObject:[dic objectForKey:@"title"]];
}
NSLog(@"OK!!");
}
[self.tableView reloadData];
[self.tableView flashScrollIndicators];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
operationQueue = [[NSOperationQueue alloc] init];
[operationQueue setMaxConcurrentOperationCount:1];
[self beginLoadingFlickrData];
self.tableView.rowHeight = 95;
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return[names count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SimpleTableIdentifier] autorelease];
}
cell.detailTextLabel.text=[names objectAtIndex:indexPath.row];
cell.textLabel.text=[pics objectAtIndex:indexPath.row];
//UIImage *image=[UIImage imageWithData:[self.lists objectAtIndex:indexPath.row]];
//cell.imageView.image=image;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
fetcher=[[FlickrFetcher alloc]init];
PhotoDetail *scroll=[[PhotoDetail alloc]initWithNibName:@"PhotoDetail" bundle:nil];
scroll.titleName=[self.pics objectAtIndex:indexPath.row];
scroll.picture = [UIImage imageWithData:[self.lists objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:scroll animated:YES];
}