Search Results

Search found 2 results on 1 pages for 'jukurrpa'.

Page 1/1 | 1 

  • iPhone - dequeueReusableCellWithIdentifier usage

    - by Jukurrpa
    Hi, I'm working on a iPhone app which has a pretty large UITableView with data taken from the web, so I'm trying to optimize its creation and usage. I found out that dequeueReusableCellWithIdentifier is pretty useful, but after seeing many source codes using this, I'm wondering if the usage I make of this function is the good one. Here is what people usually do: UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"Cell"]; // Add elements to the cell return cell; And here is the way I did it: NSString identifier = [NSString stringWithFormat:@"Cell @d", indexPath.row]: // The cell row UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell != nil) return cell; cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier]; // Add elements to the cell return cell; The difference is that people use the same identifier for every cell, so dequeuing one only avoids to alloc a new one. For me, the point of queuing was to give each cell a unique identifier, so when the app asks for a cell it already displayed, neither allocation nor element adding have to be done. In fine I don't know which is best, the "common" method ceils the table's memory usage to the exact number of cells it display, whislt the method I use seems to favor speed as it keeps all calculated cells, but can cause large memory consumption (unless there's an inner limit to the queue). Am I wrong to use it this way? Or is it just up to the developper, depending on his needs?

    Read the article

  • iPhone - NSURLConnection does not receive data

    - by Jukurrpa
    Hi, I have a pretty weird problem with NSURLRequest. I'm using them to make an asynchronous image loading in an UITableView. The first time the tableView displays, all connections from NSURLRequests open correctly but receive absolutely no data, regardless of how long I wait. But as soon as I scroll down in the tableView, the newly created requests for the new cells work perfectly! The only way for the images on top of the tableView to load is to make them disappear by scrolling down and then up again, in order to create new requests. Here is what I do in "cellForRowAtIndexPath": UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWIthFrame:CGRectMake(0, 0, 300, 60)]; AsyncUIImageView imageView = [[AsynUIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)]; imageView.tag = IMG_VIEW // an enum for tags [cell addSubView:imageView]; [imageView release]; } AsyncUIImageView imageView = (AsyncUIImageView*)[cell viewWithTag:IMG_VIEW]; // I do a few cache checks here, but if the image aint cached I do this: [imageView loadImageFromURL:@"http://someurl.com/somepix.jpg"]; // all urls are different, just an example The AsyncUIImageView inherits from UIImageView and contains an NSURLConnection which opens upon calling the loadImageFromURL method: (void) loadImageFromURL:(NSString*)filename { if (self.connection != nil) [self.connection release]; if (self.data != nil) [self.data release]; NSURLRequest* request = [NSURLRequest requestWithURL:[[NSURL alloc] initWithString:fileName] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; self.connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; if (self.connection == nil) return; self.data = [[NSMutableData data] retain]; } I've created the delegate methods "connection: didReceiveData", which appends received data to self.data and "connectionDidFinishLoading" which sets the image and closes the connection once the transfer is complete. These work, but are never called for the first requests I create. I suspect this bug to come from the main thread not giving the first requests the control so they can execute themselves, as the same behavior happens if I keep my finger on the screen after a scroll: connections open themselves, but no data is received until I stop touching the screen. What am I doing wrong?

    Read the article

1