iOS 多线程开发以及网络图片加载

NSDictionary *group=[[NSDictionary alloc]initWithObjectsAndKeys:indexPath,@"indexpath",cell,@"cell", nil];
    [NSThread detachNewThreadSelector:@selector(loadLabelTableView:) toTarget:self withObject:group];

-(void)loadLabelTableView:(NSDictionary *)group
{
    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(50, 10, 200, 30)];
    NSString *codeCharacter=[[m_listData objectAtIndex:[[group objectForKey:@"indexpath"] row]] substringWithRange:NSMakeRange(0, 2)];
    NSString *codeNumber=[[m_listData objectAtIndex:[[group objectForKey:@"indexpath"] row]] substringWithRange:NSMakeRange(3, 6)];
    NSString *codeName=[[m_listData objectAtIndex:[[group objectForKey:@"indexpath"] row]] substringWithRange:NSMakeRange(10, 4)];
    NSString *stockList=[NSString stringWithFormat:@"%@%@\t%@",codeCharacter,codeNumber,codeName];
    label.text=stockList;
    [[group objectForKey:@"cell"] addSubview:label];
}

网络图片加载方式:
-(void)loadImageCollectionView:(NSDictionary *)group
{
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 2, 70, 100)];
    NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:[[[listData objectAtIndex:[[group objectForKey:@"indexpath"] row]] objectForKey:@"images"] objectForKey:@"small"]]];
    UIImage *img=[UIImage imageWithData:data];
    imageView.image=img;
    [[group objectForKey:@"cell"]  addSubview:imageView];
}

猜你喜欢

转载自cydd.iteye.com/blog/2169528