1

I am using web services for iPhone App development. I used NSDictionary for fetching data using JSONParsing. It's coming fast from web services but it's too much slow while binding to my view/XIB.I am not getting what is the actual issue with this.Because it's working fast on android but not on iPhone.Is their any other solution or example to solve this issue.

Code -

- (void)viewDidLoad
{
    //returning cell with name & logo
    NSLog(@"activity array = %@",activityArray);
    addNameList =  [[NSMutableArray alloc]init];
    addThumbnails = [[NSMutableArray alloc]init];
    addActivityId = [[NSMutableArray alloc]init];

    for (int x=0; x<[activityArray count]; x++)
    {
        NSDictionary* toDist = [activityArray objectAtIndex:x];
        [addNameList addObject:[toDist objectForKey:@"activity"]];
        [addThumbnails addObject:[toDist objectForKey:@"icon"]];
        [addActivityId addObject:[toDist objectForKey:@"id"]];
    }

    activityList = addNameList;
    thumbnails = addThumbnails;
    activityIdList = addActivityId;
 }

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    NSString *str = [NSString stringWithFormat:@"%@",[thumbnails objectAtIndex:indexPath.row]];
    cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:str]]];
    cell.textLabel.text = [activityList objectAtIndex:indexPath.row];

    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(20,20,277,58)];
    backImage.backgroundColor = [UIColor clearColor];
    backImage.opaque = NO;
    backImage.image = [UIImage imageNamed:@"cellBackgroundImage.png"];
    cell.backgroundView = backImage;
    return cell;

}
4

2 回答 2

1

I am not getting what is the actual issue with this.

Neither are we, frankly. It's impossible to tell why your code is slow if you don't show it to us. Sounds like the real problem is that you're not sure which part of your code is slow. So let me tell you how to figure that out: profile your code.

Xcode includes a powerful tool called Instruments that lets you look at how much time your app is spending in each method, how much memory it's using, how much power, and so on. Explaining how to use it is a little too in-depth for this response, so please start with the Instruments User Guide The short version is that you can use the Product->Test menu command to launch your app under Instruments, and doing so will let you collect and analyze a number of different kinds of performance data. If you find a high-level method that seems to be taking longer than it should, you can drill down into the method and look at the methods that it calls, and the methods that those methods call in turn.

Armed with the information that you can get from Instruments, you won't have to wonder about why your code is slow -- you'll be able to find the answer empirically.

于 2013-08-19T07:56:44.337 回答
0

In case you haven't figured out how to load the image data in the background

NSString *str = [NSString stringWithFormat:@"%@",[thumbnails objectAtIndex:indexPath.row]];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{

    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]];

    dispatch_async(dispatch_get_main_queue(), ^{
        cell.imageView.image = [UIImage imageWithData:data];
    });
});
于 2013-08-19T09:27:07.463 回答