Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-03-2011, 12:54 PM   #1 (permalink)
learner2011
 
Join Date: Mar 2011
Posts: 115
ashwinr87 is on a distinguished road
Default asynchronous calls to database in ios

I have 4 UITableView's on my iPAD application. I load the data on them using a function
Code:
loadData
,which is there in all the 4 TableViewController.m files, which makes calls to the database.

So, I would be doing something like this

Code:
[aView loadData];
[bView loadData];
[cView loadData];
[dView loadData];
Where aView, bView, cView and dView are the view controllers of the UITableView's.

However, the database calls happen synchronously and hence only after the data is retrieved from the [aView loadData] function, does the [bView loadData] function get called and so on.

This affects my performance.

I would like to know if there is a way I can asynchronously make calls to the database/ asynchronously make calls to functions which calls database.

It would be great if someone could help me out with this.
ashwinr87 is offline   Reply With Quote
Old 10-03-2011, 01:15 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Have you tried spawning a new thread for each?
smithdale87 is offline   Reply With Quote
Old 10-03-2011, 01:20 PM   #3 (permalink)
learner2011
 
Join Date: Mar 2011
Posts: 115
ashwinr87 is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
Have you tried spawning a new thread for each?
I was thinking about that, but I am not sure how to do that and was looking for guidance on how to do the same.
ashwinr87 is offline   Reply With Quote
Old 10-03-2011, 03:49 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

You can spawn a new thread to run your method using
Code:
[aView performSelectorInBackground:@selector(loadData)]
Beware tho, that the method (loadData) must not directly mess with the main thread (i.e no UI objects). If its needed, it must be synchronized with the main thread using performSelectorOnMainThread
nobre84 is offline   Reply With Quote
Old 10-03-2011, 07:06 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by ashwinr87 View Post
I have 4 UITableView's on my iPAD application. I load the data on them using a function
Code:
loadData
,which is there in all the 4 TableViewController.m files, which makes calls to the database.

So, I would be doing something like this

Code:
[aView loadData];
[bView loadData];
[cView loadData];
[dView loadData];
Where aView, bView, cView and dView are the view controllers of the UITableView's.

However, the database calls happen synchronously and hence only after the data is retrieved from the [aView loadData] function, does the [bView loadData] function get called and so on.

This affects my performance.

I would like to know if there is a way I can asynchronously make calls to the database/ asynchronously make calls to functions which calls database.

It would be great if someone could help me out with this.
Why do you call loadData on a table view of a view controller that isn't the front view controller?

That's wrong for a number of reasons.

First, nobody but the owning view controller should manipulate its views directly. Doing that is a huge violation of encapsulation in object oriented programming. It's corrupts the MVC design pattern.

Second, the other table views may not even be loaded if they are on the frontmost view controller. The system can unload the views of any view controller but the front one at any time to free up memory.

Third, it's taking time to do something that doesn't have any visible result, and causing the UI on the current view controller to lag.

You should add a "dataHasChanged" method to each of your view controllers, and call that. Then, when the view controller's viewWillAppear (or viewDidAppear) method gets called, it can call reloadData itself if its data has changed.)
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
asynchronous, coredata, ios, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 385
17 members and 368 guests
13dario13, 7twenty7, eski, EvilElf, glenn_sayers, HemiMG, iOS.Lover, jarv, LunarMoon, n00b, pbart, Pudding, sacha1996, Sami Gh, UMAD, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:20 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0