Ios 在已排序的UITableViewCell上添加MySQL数据库中的图像

Ios 在已排序的UITableViewCell上添加MySQL数据库中的图像,ios,objective-c,image,uitableview,nsdictionary,Ios,Objective C,Image,Uitableview,Nsdictionary,我不熟悉Xcode和Objective-c,我想制作一个按字母顺序排序的联系人列表,其中也包含图像。请查收参考资料 这段代码告诉了我所需要的一切,但问题是我使用MySQL中的名称和图像,而不是像那样硬编码 我已将数据导入NSDictionary,结果如下: audiences=({name="ABDUL",id="1",photo="asd.png"},{name="ABDUL",id="2",photo="qwe.png"}); 我需要做什么才能将名称和照片只添加到这两个项目中,而不向UIT

我不熟悉Xcode和Objective-c,我想制作一个按字母顺序排序的联系人列表,其中也包含图像。请查收参考资料

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

我已将数据导入NSDictionary,结果如下:

audiences=({name="ABDUL",id="1",photo="asd.png"},{name="ABDUL",id="2",photo="qwe.png"});
我需要做什么才能将名称和照片只添加到这两个项目中,而不向UITableViewCell添加id? 我以前使用过代码,但只显示排序后的名称,我不知道如何调用图像

这就是我解析名称的方式,以便在列表中获取它:

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];
}
在这里,我需要将图像字符串放在这里:

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

   return imageFilename;
}

我需要你的帮助

图像是否在您的数据库中?你是说,你在使用sqlite还是核心数据? 这是sqlite中简单选择的代码:

const unsigned char*myBlob=sqlite3\u column\u blobsqlite3\u stmt*,column; ifmyBlob!=空的{ 值=[NSString stringWithUTF8String:const char*myBlob];
}

没有。我使用php web服务从MySQL数据库获取数据,我没有使用sqlite或CoreData。但是,我不认为这是问题所在,因为我已经获取了所有数据并将其放入NSDictionary。这是显示{受众={name=ABDUL;id=1;photo=0192038409.jpg},{name=ELSA;id=2;photo=647263846.jpg},…}@etc}@davidbemerguy您是说从ws检索的字典为您带来了图像的名称?而不是它的数据?不是。ws带来了上面的数据。然后我创建了另一个字典,它只有我按照教程中的名称,然后用户希望图像也添加到列表中。但我不知道如何根据他们的姓名或id添加图像。请帮助@DavidBemerguy