Posts Tagged ‘uitableview’

CopyableCell: A UITableViewCell Subclass for Making Cells Copyable

June 9th, 2011 Ahmet Ardal No comments

UITableView is one of the most frequently used views of Cocoa Touch framework. We almost always use it whenever we need to display a collection of data items. There are lots of ways to customize the appearance and functionality of a UITableView to make it meet the application’s needs. Sometimes we might want to enable users to copy UITableViewCells’ content.



Read more…

Loading Images Asynchronously in Background in Cocoa Touch

February 7th, 2011 Ahmet Ardal 4 comments

While developing apps for iOS devices, we, in some cases, need to load some remote resources asynchronously in background without making the main thread and the UI become unresponsive. This demo project explains loading images from the web but the same technique could be applied for loading any type of resources, i.e.: audio files, text files, mail headers… to name a few. There are several possible approaches for implementing background loading in Cocoa Touch. All are based on the same simple principle: perform resource loading tasks on some other thread(s) other than the main/UI thread and make UI updates(if any needed) on main thread. There are two nice classes in Cocoa Touch framework which I used for this demo project: NSOperationQueue and NSInvocationOperation. Although NSOperationQueue provides some other complex features, what we simply need here is just:

  1. Create an NSOperationQueue object,
  2. Create NSInvocationOperation objects with target, selector and task data(in our case this is the image url)
  3. Add the NSInvocationOperation object to the NSOperationQueue we created
  4. Run the operation queue to process queued operations(in our case, an operation is to download an image from the internet)
  5. If there is need for any updates on the UI after a task is processed, i.e. an image is downloaded, perform those updates on the main thread by calling one of the performSelectorOnMainThread methods of the NSObject class.

That’s all it simply takes. Now time to show some parts of the code (which i consider worthwhile to have a look at). I believe the code is self-explanatory enough to be understood without any further explanation on what it does.
Read more…