Creating Objects on the Fly

Discussion in 'iOS Programming' started by tdewitt274, Nov 4, 2012.

  1. tdewitt274 macrumors newbie

    Nov 4, 2012
    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:

    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!



    NOTE: I did post this to another forum, but found it was not the right audience. Sorry for the double post.
  2. admanimal macrumors 68040

    Apr 22, 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.
  3. tdewitt274 thread starter macrumors newbie

    Nov 4, 2012
    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.

    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.
  4. ArtOfWarfare macrumors G3


    Nov 26, 2007
    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:

    Of course, a model by itself doesn't do a whole lot.
  5. tdewitt274 thread starter macrumors newbie

    Nov 4, 2012
    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!
  6. ArtOfWarfare macrumors G3


    Nov 26, 2007
    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.

Share This Page