What would be the best way to create a long list of editable values?

Discussion in 'iOS Development' started by bamhm182, May 22, 2009.

  1. bamhm182

    bamhm182 Member

    Joined:
    Mar 2, 2009
    Messages:
    544
    Likes Received:
    0
    Device:
    3G iPod touch
    I need some help with a program I'm writing.

    I'm working on this program that needs to be able to have about 50 objects on a view, each with their own value, than take a number from a text box attached to each object, multiply itself by that number, than feed the new number into a larger equation. Is this possible to do? If so, how?

    Also, I want to have a button that the user can click to run the equation after they've entered everything that they need to. Than when they click on the button, I was wanting to have an alert pop up with the answers on it. Is that possible to do? If so, how? Can the message of an alert have breaks? The app would look better if it was like:

    Final Value 1: XXX
    Final Value 2: XXX
    Final Value 3: XXX

    Also, how can you write equations? I know you can do degreesToRadian fairly easy, but what about something a bit more complex. I'm not certain what the equation is yet because I still need to talk to the guy that has the equation. However, I'd assume it needs to be something like this, where object is an unaltered number, and value is an object multiplied by a number:

    Object 1 - (Value 1+Value 2+Value 3+etc...)

    If you need clarification on something, feel free to ask.

    EDIT: I've almost got UIScrollView figured out. I've got my app to use it like a view, but I can't figure out how to make it actually scroll... If anyone can tell me how to make it scroll, please do.
  2. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Use an array?
  3. bamhm182

    bamhm182 Member

    Joined:
    Mar 2, 2009
    Messages:
    544
    Likes Received:
    0
    Device:
    3G iPod touch
    I'll look into that Pelaez. Thanks.

    When setting your IBOutlets, can you include numbers? For example, can I use:

    Code:
    @interface DropViewController : UIViewController
    {
             IBOutlet      UITextField     Object1Field;
    }
    or would it be better to use:

    Code:
    @interface DropViewController : UIViewController
    {
             IBOutlet      UITextField     ObjectOneField;
    }
    Thanks.
  4. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    Interface Builder tells you if you can't use something as a name, such as try putting a apostrophe in one such as "chicken'saresocool" it would not allow you and you would see some little red text telling you so.
  5. bamhm182

    bamhm182 Member

    Joined:
    Mar 2, 2009
    Messages:
    544
    Likes Received:
    0
    Device:
    3G iPod touch
    Thanks chicken. Looks like it doesn't like the numbers, or at least not the way I was wanting to use them. Doesn't matter anyways, I was just wanting to be lazy and not have to write out all the numbers multiple times, but I wrote them all out already, so I'm fine.

    Also, would this be the correct way to write an equation? If I'm not mistaken, this would go at in the .h file, so if you've got a nib called Blue that you want to use an equation in, it'd go into BlueViewController.h, right?:

    Code:
    #define ObjectOneValue = 25
    #define ObjectTwoValue = 50 
    #define ObjectThreeValue = 75 
    #define ObjectFourValue = 100 
    #define ObjectOneValue * ObjectTwoValue = a
    #define ObjectThreeValue * ObjectFourValue = b
    #define Answer = a + b
    Obviously, the values wouldn't make sense because they're all given to you in the example above, but I didn't feel like writing variables yet, but is this the right way to write equations and is this the right location?
  6. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Just write a simple array. Don't even make it an NSArray if you don't want to.
  7. bamhm182

    bamhm182 Member

    Joined:
    Mar 2, 2009
    Messages:
    544
    Likes Received:
    0
    Device:
    3G iPod touch
    Alright, I think I've got it. I found a tutorial on Arrays here.

    I'm going to have different classes, so I should have separate arrays for those classes, right?

    EDIT:Would I write it like this?:

    ColorsViewControl.h
    Code:
    #import <UIKit/UIKit.h>
    
    @interface ColorsViewController : UIViewController
    {
         NSArray     *listOfWarmColors;
         NSArray     *listOfColdColors;
         NSArray     *listOfOtherColors;
    }
    
    @end
    
    ColorsViewControl.m
    Code:
    #import "ColorsViewController.h"
    
    @implementation ColorsViewController
    
    - (void)viewDidLoad
    {
    	[super viewDidLoad];
    	
    	listofWarmColors = [[NSArray alloc] init];
    	
    	[listofWarmColors addObject:@"(Warm Color 1)"];
    	[listofWarmColors addObject:@"(Warm Color 2)"];
    	[listofWarmColors addObject:@"(Warm Color 3)"];
    	
    	self.navigationItem.title = @"Warm Colors";
    
    	listofColdColors = [[NSArray alloc] init];
    	
    	[listofColdColors addObject:@"(Cold Color 1)"];
    	[listofColdColors addObject:@"(Cold Color 2)"];
    	[listofColdColors addObject:@"(Cold Color 3)"];
    	
    	self.navigationItem.title = @"Cold Colors";
    
    	listofOtherColors = [[NSArray alloc] init];
    	
    	[listofOtherColors addObject:@"(Other Color 1)"];
    	[listofOtherColors addObject:@"(Other Color 2)"];
    	[listofOtherColors addObject:@"(Other Color 3)"];
    	
    	self.navigationItem.title = @"Other Colors";
    }
    
    - (void)dealloc
    {
        [listofWarmColors release];
        [listofColdColors release];
        [listofOtherColors release];
        [super dealloc];
    }
    
    
    Also, how do you add a value for each color?
  8. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    If they're just values, don't make them objects. Why waste the memory.

    Again, just use a simple array.
  9. bamhm182

    bamhm182 Member

    Joined:
    Mar 2, 2009
    Messages:
    544
    Likes Received:
    0
    Device:
    3G iPod touch
    The purpose of my Application is to find out how many things someone has by them punching in how many things they have into a text box. Than the application takes how many of each thing they have and multiplies it by how much it's worth. Than after it does that for about 50 things,(not all 50 things will be input at once, but I need to give them an option for about 50 things, preferably all on one view so they don't have to go digging) it takes the value of each individual thing and uses them in an equation to get a total number. I'm still waiting on the person with the equation to give me the equation.

    I'm not sure how to do that.

    EDIT: To help better explain, it should have an interface similar to this:

    Please Register or Log in to view images



    The user will probably use 1 thing from section 1, 1 thing from section 2, etc. however, I'd like all the choices to show up, just in case they need more than 1 from each section. When I'm done, you'll be able to input values for each object in the UIScrollView, than it'll take the value from the text box, multiply it by how much their corresponding object is worth, than plug it into an equation, who's answer will appear at the bottom of the screen.

    EDIT 2: YES! I got 1 more component working! I'm so proud of myself, even though it's just about the EASIEST thing ever. I've spent all this time trying to figure out how the hell you use a UIScrollView, downloaded MANY source codes, none of their methods worked, but I finally got it. I now know how to use UIScrollViews, and it's just about the easiest thing you can do.

    Please Register or Log in to view images

    I think what I was doing was thinking that the first part of code initiated it or something, so I was including it, than when I put in the scrollView.contentSize, it'd get confused because I had already put in values at the top. I did away with the first line and kept the contentSize and found out it's easy.

    EDIT 3: Alright, so now I'm almost completely done. SkylerEC, it'd be AWESOME if you could give me a sample of what you mean by array, as well as where to put it, because for some reason, I'm just not getting it.

    EDIT 4: So I started looking around here, as apposed to google, and found your Decoder Ring post. Am I supposed to do something like that?

Share This Page