كيفية عرض الصورة في خلية؟
-
19-09-2019 - |
سؤال
أنا جديد في تطوير iPhone. أريد عرض الصورة في كل خلية. لدي فقط عنوان URL للصورة في صفيف. يرجى مساعدتي. شكرا.
المحلول
//put this code in cellForRowAtIndexPath.... I'm assuming you have an array of url's that point to images
id urlPath = [yourArray objectAtIndex:indexOfImage];
NSURL *url = [NSURL URLWithString:urlPath];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//insert an image into your cell
cell.imageView = image;
ربما هناك طريقة أكثر فعالية للقيام بذلك، لكنها طريقة لائقة للبدء في تخصيص خلايا الجدول المطولين. ImageView هي واحدة من العديد من خصائص الفصل القديم.
قراءة متعمقة.... المرجع ayatableviewcell
نصائح أخرى
يجب إلقاء نظرة على رمز نموذج Apple هذا، إنه رائع ويظهر كيفية تطبيق ما تحتاجه بالإضافة إلى الأشياء الأخرى المفيدة:خلايا عرض الجدول المتقدمة
لا تنتمي إلى StackOverflow