Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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 11-06-2008, 05:31 PM   #1 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 4
Default A Loop to load data

To load 10 records and be able to use them later I load them one by one (please don't laugh, i'm a beginner). Can someone show me how to write a loop

DataBaseSQLiteAppDelegate *appDelegate = (DataBaseSQLiteAppDelegate *)[[UIApplication sharedApplication] delegate];
Data *datax = (Data *)[appDelegate.dataInformation objectAtIndex:indexPath.row];
Data *datax0 = (Data *)[appDelegate.dataInformation objectAtIndex:0];
Data *datax1 = (Data *)[appDelegate.dataInformation objectAtIndex:1];
Data *datax2 = (Data *)[appDelegate.dataInformation objectAtIndex:2];
Data *datax3 = (Data *)[appDelegate.dataInformation objectAtIndex:3];
Data *datax4 = (Data *)[appDelegate.dataInformation objectAtIndex:4];
Data *datax5 = (Data *)[appDelegate.dataInformation objectAtIndex:5];
Data *datax6 = (Data *)[appDelegate.dataInformation objectAtIndex:6];
Data *datax7 = (Data *)[appDelegate.dataInformation objectAtIndex:7];
Data *datax8 = (Data *)[appDelegate.dataInformation objectAtIndex:8];
Data *datax9 = (Data *)[appDelegate.dataInformation objectAtIndex:9];
listContent = [[NSMutableArray alloc] initWithObjects:datax0.contact, datax1.contact, datax2.contact, datax3.contact, datax4.contact,
datax5.contact, datax6.contact, datax7.contact, datax8.contact, datax9.contact, nil];
cell.text = [filteredListContent objectAtIndex:indexPath.row];
mgomez is offline   Reply With Quote
Old 11-06-2008, 05:39 PM   #2 (permalink)
New Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
Default

Code:
NSMutableArray *listContent = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i++) {
    Data *data = (Data *)[appDelegate.dataInformation objectAtIndex:i];
[listContent addObject:data];
}
RickMaddy is offline   Reply With Quote
Old 11-06-2008, 11:27 PM   #3 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 14
Default

Does it work for values other than 10?
Alex.be is offline   Reply With Quote
Old 11-07-2008, 12:20 AM   #4 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 802
Default

Just change the 10 to something else. You really should consider at least downloading the free Intro to Objective-C at Apple's site. Loops are very basic to programming.
scottiphone is offline   Reply With Quote
Old 11-07-2008, 12:33 AM   #5 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 14
Default

Sorry it was sarcasm. I do believe that posts like these should not be answered. At least not in this manner. There are more and more completely clueless users asking very basic questions on these forums, drowning the few interesting subjects with questions that have either been answered over and over again, or especially now demonstrate a total lack of ability to read even the simplest of documents or procedures or even the most basic programming knowledge.

Understand me, I welcome all new users to the community, and the more of us the better, but I do feel that it is everybody's duty to observe a minimum of patience before posting any question, and understanding than instead of getting things done by other people it will be
- faster
- more effective
- the ONLY way
to read and experiment and understand the documentation.

Basically, if you can't write a loop, there is no amount of posting to these forums, however detailed the answers, that will make you ever get something accomplished. You have to absorb a minimal set of information by yourself or eveyr single step of your development will be a road block. Through that kind of trial and error it would take years to get a GUI hello world done.

If you don't know where to start, type "objective-c" and "cocoa iphone tutorial" in google.

I am open to criticism if this reply is seen as elitist, though I would like to believ that it would be salvatory instead of perpetuating the idea that you can get things done by asking questions to the community when you encounter a problem. It should ALWAYS be a last resort, not even not to distrurb said community, but because it will be 1000 times more efficient to
1. read and assimilate various amount of documenttion while looking for an answer
2. learn to solve problems by yourself.
3. Google is your friend for 99% left unanswered - developping good search skills and several sources of information is crucial. It will always be faster than wait for an answer from a human on the forums, especially since the more general the question (thus when it hasnt been researched) the less useful the answer in actual code terms (sure now you can use a loop, but you still don't know when to use one, what iterators are, when to use a while, how to write an inverse loop, how to break in special cases, etc... all of which would take you 5 minutes to find out if you typed "obective-c loop syntax in google" and read the first 5 links, discard the 2 worst, bookmark the best one, read, understand, assimilate, learn, rinse, repeat...)

Last edited by Alex.be; 11-07-2008 at 12:40 AM.
Alex.be is offline   Reply With Quote
Old 11-07-2008, 07:23 AM   #6 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 486
Default

Alex.be you are absolutely correct. I may be a new poster here (long time lurker) but it blows me away the number of "plz u can writ mai prg 4 mee?" type posts there are. Not the OP in this case, at least he learned how to load the data he needed in by himself, just not the most efficiently. I'm still new to the Objective C language, but have been learning a lot from the knowledgeable posters by lurking and reading PDFs and tutorials- not by asking questions.

Somehow everybody and their brother found the download link to the SDK but missed the 10 tons of sample programs, video and PDF guides right below it in the iPhone Dev Center!

My favorite one this week was in another forum (Macrumors I think) where someone was asking if the SDK was a GUI editor that built your code and app for you, point and click like "Frontpage".

Hopefully, with a bunch of sweat and reading the docs my first app will make it in the store by the end of the year. I went a bit ambitious for my first time out and started in with a game immediately. But that's only because I had previous programming and art background. *lurks more*
CommanderData is offline   Reply With Quote
Reply

Bookmarks

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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,185
Threads: 38,957
Posts: 170,914
Top Poster: smasher (2,565)
Welcome to our newest member, JaredJohnson325
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:57 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0