Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 4, 2012, 11:44 AM   #1
tdewitt274
macrumors newbie
 
Join Date: Nov 2012
Creating Objects on the Fly

Hello All!

First off, I'd like to put it out there. I'm new to OOP. I mostly do web scripting in my spare time (VBScript and JavaScript). However, a friend of mine suggested that I give creating iPod apps a try. So, here it goes...

I have a JavaScript page that creates a tracker. For simplification, it takes user input of the Name and Age and sorts it based on Age. To do this, I have a form that allows the user to enter the data and a button to add values to a <div> container (affectionately named "divBody"). Here's a snippet of what the code looks like:

PHP Code:
function PutErThere (txtName,intAge) {
CurrInfo document.getElementById("divBody");

CurrInfo.innerHTML += "<span style='width:120;'>"+txtName+"</span>";
CurrInfo.innerHTML += "<input type='text' style='width:40; text-align:center;' value='"+intAge+"' name='txtVal1'>";

So, as you can see, it takes the input and creates a "label" and a "text box". So, here's my problem: How do I get these objects to appear on the screen in Objective C?

I can figure out the rest of the sorting and such by trial and error. But I don't know how to add the fields while the code is running. I understand that the objects can be programmed in on the code side using the XCode program. However, the users can enter more than expected.

OK, for extra credit, here's another question. I'm sure that once I find an answer to the above question that this may fall into line. In the end, I would like to have a "Person" Object that stores the Name and Age passed. Is it possible to make the Object function like the label and text box as described above? Just a thought.

Any help is greatly appreciated!

Thanks

Todd

NOTE: I did post this to another forum, but found it was not the right audience. Sorry for the double post.
tdewitt274 is offline   0 Reply With Quote
Old Nov 4, 2012, 12:12 PM   #2
admanimal
macrumors 68040
 
Join Date: Apr 2005
Your question basically amounts to "how do I program in Objective-C," which no one is going to be able to teach you on here. There are mountains of resources online that can get you started.

My one suggestion would be to avoid trying to think of the process as translating Javascript into Objective-C. The languages are so entirely different in scope and purpose that you are not going to get anywhere with that approach. Creating an app in Objective-C has nothing to do with HTML.
admanimal is offline   0 Reply With Quote
Old Nov 4, 2012, 12:58 PM   #3
tdewitt274
Thread Starter
macrumors newbie
 
Join Date: Nov 2012
Quote:
Originally Posted by admanimal View Post
Your question basically amounts to "how do I program in Objective-C," which no one is going to be able to teach you on here. There are mountains of resources online that can get you started.
Yes, and no. I have plenty of books that I have read, in whole or part, for programming in Objective C (Programming in Objective-C 2.0, Beginning iPad Application Development, Beginning iPhone 3 Development, Learn Objective-C on the Mac). However, none of these books have shown me a way of creating the desired result. If I missed something in those books, I am more than happy to review the appropriate sections (except in the Beginning iPhone 3 Development book, that author is worthless).

As far as searching online, I lack the words to describe what I am attempting. If you have a better way of stating "create an object at run time in Objective-C" to find a result that will accomplish my goal, I am all ears and will investigate those options.

Quote:
Originally Posted by admanimal View Post
My one suggestion would be to avoid trying to think of the process as translating Javascript into Objective-C. The languages are so entirely different in scope and purpose that you are not going to get anywhere with that approach. Creating an app in Objective-C has nothing to do with HTML.
Yes, not all languages are alike. And yes, HTML has nothing to do with Objective-C. I'm actually referring to JavaScript. JavaScript has a similar syntax and basic programming structures. While JavaScript is forgiving on the requirement of declaring variables (and is not a full OOP), with a little bit of work I have converted one of my JavaScript programs to C# (not that different from Objective-C).

That being said, JavaScript is a language that I know and can use code examples to have a visual representation of the concept in question. I have converted VBScript to JavaScript, ASP to PHP, even used JavaScript to port an idea over to Lua. The end result is what matters, the programming is the adventure!

If there is no way of doing what I'm attempting through my example, let me know. I'll figure out a different way of doing it (maybe limiting to populate only the amount of pre-placed objects as stated in the original post).

I apologize if this comes off as rude. It is not meant to be. I am serious about converting my idea into a final product. My light hearted original post was an attempt to be softer than "here's my problem, what's the solution". I am not looking for the solution. I'm looking to learn the solution.
tdewitt274 is offline   0 Reply With Quote
Old Nov 4, 2012, 01:08 PM   #4
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by tdewitt274 View Post
In the end, I would like to have a "Person" Object that stores the Name and Age passed.
I wrote a little tutorial for class a writing class a few weeks ago... it covers creating a simple object that just stores some data in Obj-C on this page:

https://sites.google.com/site/unit2iostutorial/model

Of course, a model by itself doesn't do a whole lot.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Nov 4, 2012, 01:25 PM   #5
tdewitt274
Thread Starter
macrumors newbie
 
Join Date: Nov 2012
Quote:
Originally Posted by ArtOfWarfare View Post
I wrote a little tutorial for class a writing class a few weeks ago... it covers creating a simple object that just stores some data in Obj-C on this page:

https://sites.google.com/site/unit2iostutorial/model

Of course, a model by itself doesn't do a whole lot.
That is helpful! This process of "flipping through" a listing of people will work for a different version of my original. In that version, I store the objects in an array and go on to the next entry after I'm finished with it. I will keep that in mind!
tdewitt274 is offline   0 Reply With Quote
Old Nov 4, 2012, 02:50 PM   #6
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by tdewitt274 View Post
That is helpful! This process of "flipping through" a listing of people will work for a different version of my original. In that version, I store the objects in an array and go on to the next entry after I'm finished with it. I will keep that in mind!
Just as a quick warning: The finished project at the end of the tutorial doesn't actually work. I'm in a class full of business, journalism, and english majors, so despite how professionally the website may appear, it's actually all stuff I wrote on the fly and hardly tested. I'm not sure which part doesn't work, but I suspect it's in the Controller section somewhere.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Bubbles Fly Game - Fly Without Wings LeeTommy iPhone and iPod touch Apps 0 May 30, 2013 11:04 PM
Bubbles fly - Fly without wings LeeTommy iPhone and iPod touch Apps 0 May 12, 2013 10:24 PM
Creating Objects on the Fly tdewitt274 iPhone and iPod touch Apps 1 Nov 4, 2012 11:25 AM
Fly The Fly - New Arcade Game DilekPL iPhone and iPod touch Apps 3 Jul 26, 2012 03:39 PM
Creating a localized table index on the fly idelovski iPhone/iPad Programming 5 Jul 19, 2012 07:25 PM

Forum Jump

All times are GMT -5. The time now is 05:25 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC