Facebook의 사진 링크를 파싱하여 iOS 앱에 표시하는 App을 만들려고합니다 (tableView에 표시). 하지만 JSON 파일을 파싱하고 다운로드해야하는 배열에 추가 한 후에는 아무 것도 표시되지 않습니다.JSON 파일의 링크를 파싱하여 다운로드하십시오.
- (void)viewDidLoad
{
self.edgesForExtendedLayout = UIRectEdgeNone;
[super viewDidLoad];
items = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/HuppFotografie/photos/uploaded/?fields=id,name,picture"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
connection = [NSURLConnection connectionWithRequest:request delegate:self];
if (connection) {
webData = [[NSMutableData alloc]init];
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"fail with error");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSArray *arrayOfData = [allDataDictionary objectForKey:@"data"];
for (NSDictionary *dicton in arrayOfData) {
NSString *picture = [dicton objectForKey:@"picture"];
[items addObject:picture];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 250.0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"MyImageCell";
ImageCell *cell = (ImageCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
if (cell == nil) {
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ImageCell" owner:self options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (ImageCell *)currentObject;
break;
}
}
}
// Here we use the new provided setImageWithURL: method to load the web image
[cell.imageView setImageWithURL:[NSURL URLWithString:[items objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@"Placeholder.jpg"]];
cell.imageSource.text = [items objectAtIndex:indexPath.row];
return cell;
}
난 정말 왜하지 않습니다 여기에 코드입니다. 이 질문이 어리 석다면 미안하지만 취미로 코딩하고 그 위대한 경험이 없다면.
connectionDidFinishLoading에서 allDataDictionary, arrayOfData 및 items 배열의 값을 확인 했습니까? –
'connectionDidFinishLoading'끝에 테이블보기를 다시로드하려고 시도했을 수 있습니다. 편집 : 자리 표시 자 이미지가 보이십니까? 그렇지 않다면 위의 제 제안이 정확해야합니다. –
네 자리 표시자가 표시되지 않습니다 ... 그래서 당신의 제안은 정확할 것입니다. 나는 내일 집에 없기 때문에 오늘 그것을 확인하십시오. 귀하의 빠른 대답을 주셔서 감사합니다 –