私の .m ファイルでは、次のことを行っています。
Web 経由でデータを取得し、json 配列を解析して NSMutable 配列に保存します。これらのデータは画像の URL (画像はサーバー上にあります) であり、カスタム セルに設定したいと考えています。各セルには 2 つのイメージビューがあります。
データを正しく解析しています。私はそれらを正しく保管します。それらの値が印刷されているのを確認できます。ブラウザーでそれらを開くと、それらは正しい値です。
私のセルに私のリソースから静的な画像を配置すると、それらを見ることができます。
しかし、URLからそれらを設定しようとすると、何も表示されません。
ここに私のコードがあります:
データを取得する場合:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"connectionDidFinishLoading");
NSLog(@"Succeeded! Received %d bytes of data",[self.responseData length]);
// convert to JSON
NSError *myError = nil;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&myError];
images_url= [NSMutableArray new];
for (NSDictionary *alert in json ){
NSString* image = [alert objectForKey:@"image"];
[images_url addObject:image];
}
[self.myTable reloadData];
}
ここで、myTable は合成済みの TableView です。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int i=[images_url count]/2;
return i;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier=@"ListTableCell";
//this is the identifier of the custom cell
ListsCell *cell = (ListsCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ListsCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
/*NSString *url_left=[images_url objectAtIndex:(indexPath.row*2)];
NSLog(@"Left url is:%@",url_left);
NSString *url_right=[images_url objectAtIndex:(indexPath.row*2+1)];
NSLog(@"Right url is:%@",url_right);*/ THEY ARE PRINTED HERE
NSURL *url_left=[NSURL URLWithString:[images_url objectAtIndex:(indexPath.row*2)]];
cell.Left.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:url_left]];
NSURL *url_right=[NSURL URLWithString:[images_url objectAtIndex:(indexPath.row*2+1)]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 81;
}
リロードデータを削除すると、正しい行数ではなく値が表示されるため、必要です。
誰でもここで何が間違っているかを知ることができますか?