在已sorting的UITableViewCell上添加来自MySQL数据库的图像

我是Xcode和Objective-C的新手,我想要制作一个按字母顺序sorting的联系人列表也有图片。 请检查这个参考。

这段代码告诉我我需要的一切,但问题是我使用MySQL的名称和图像,而不是像这样的硬编码。

我已经将数据导入NSDictionary,这是结果:

audiences=({name="ABDUL",id="1",photo="asd.png"},{name="ABDUL",id="2",photo="qwe.png"}); 

我需要做什么来添加名称和照片(只有2项,没有ID)到UITableViewCell? 我以前使用过这个代码,但只显示sorting的名称,我不知道如何调用图像。

这是我parsing的名字,所以我可以抓住它的名单:

 NSMutableDictionary* audict = [NSMutableDictionary dictionary]; for (NSDictionary* person in dataDict[@"audience"]){ NSString* name = person[@"name"]; if (![name length]) continue; NSRange range = [name rangeOfComposedCharacterSequenceAtIndex:0]; NSString* key = [[name substringWithRange:range] uppercaseString]; NSMutableArray* list = audict[key]; if (!list){ list = [NSMutableArray array]; [audict setObject:list forKey:key]; } [list addObject:name]; audiences=audict; audienceSectionTitles = [[audiences allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; audienceIndexTitles = @[@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z"]; 

这是代码执行的地方

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. NSString *sectionTitle = [audienceSectionTitles objectAtIndex:section]; NSArray *sectionAudience = [audiences objectForKey:sectionTitle]; return [sectionAudience count]; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [audienceSectionTitles objectAtIndex:section]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; // Configure the cell... NSString *sectionTitle = [audienceSectionTitles objectAtIndex:indexPath.section]; NSArray *sectionAudience = [audiences objectForKey:sectionTitle]; NSString *audience = [sectionAudience objectAtIndex:indexPath.row]; UIFont *myFont = [ UIFont fontWithName: @"Helvetica" size: 12.0 ]; cell.textLabel.font = myFont; cell.textLabel.text = audience; cell.imageView.image = [UIImage imageNamed:[self getImageFilename:audience]]; return cell; } - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return audienceIndexTitles; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { return [audienceSectionTitles indexOfObject:title]; } 

在这里我需要把我的图像string:

 - (NSString *)getImageFilename:(NSString *)audience { NSString *imageFilename = @"profile.png"; return imageFilename; } 

请我需要你的帮助^^;

数据库中的图像是? 你的意思是MySQl,你使用的是SQLite还是Core Data? 这是在sqlite中简单select的代码:

const unsigned char *myBlob = sqlite3_column_blob(sqlite3_stmt *, column); if(myBlob != NULL){ value = [NSString stringWithUTF8String:(const char *)myBlob]; }