У меня есть словарь со словарем.
В словаре у меня есть строка под названием «cellPic», которая имеет адрес URL-адреса изображения.
Я пытаюсь заполнить мой вид таблицы изображениями, которые я надел на свою учетную запись 0box, прочитал их через строку plist.
(«arrayFromPlist» мой массив)
Проблема заключается в том, что, когда я запустить его, я получаю сообщение об ошибке в консоли:
[__NSCFDictionary objectAtIndex]: непризнанные селекторЧтение url изображения из строки plist
Это мой код:
-(void) readPlistFromDocs
{
// Path to the plist (in the Docs)
NSString *rootPath =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"Data.plist"];
NSLog(@"plistPath = %@",plistPath);
// Build the array from the plist
NSMutableArray *arrayFromDocs = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
if (arrayFromDocs)
{
NSLog(@"\n content of plist file from the documents \n");
NSLog(@"Array from Docs count = : %d", [arrayFromDocs count]);
}
arrayFromPlist = [[NSArray alloc] initWithArray:arrayFromDocs];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Returns the number of rows in a given section.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arrayFromPlist count];
NSLog(@"Array SIZE = %d",[arrayFromPlist count]);
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSURL *url = [[NSURL alloc] initWithString:[[arrayFromPlist objectAtIndex:indexPath.row] objectForKey:@"cellPic"]];
NSData *urlData = [[NSData alloc] initWithContentsOfURL:url];
[[cell imageView] setImage:[UIImage imageWithData:urlData]];
return cell;
}
Мой другой вопрос - как я могу загрузить асинхронные изображения, когда я прочитал URL из строки Plist?
Я попытался найти пример для этого, но я нашел только асинхронный без uisng plist.
Спасибо.