Newbie question

Discussion in 'iPhone/iPad Programming' started by AdrianK, Aug 6, 2011.

  1. macrumors 68020

    I'm currently trying to get to grips with the iOS SDK and Objective-C in general, and I've started working on a basic app.

    My 'app' currently has a UITextField, UIButton and UIAlertView which just displays what the user has typed in to UITextField. This is all taking place in ViewController.(h/m). UITextField and UIButton are in viewDidLoad and UIButton calls UIAlertView.

    I have some code (written in C) which I want to use to manipulate the input and generate an output for UIAlertView, but I'm not sure how to do that.

    I'm guessing I'd need to add the (number crunching) code to main, move UITextField outside of viewDidLoad, call it from main (to capture the entry), then call UIAlertView in ViewController from main with the output?

    Thanks in advance.
  2. macrumors 6502

    Perhaps you could direct your UIButton to a -(void) or IBAction which contains only the UIAlertView?

    For what you are practicing with, don't bother playing with main.

    Can you post your code thus far?
  3. AdrianK, Aug 6, 2011
    Last edited: Aug 6, 2011

    macrumors 68020

    I did try directing UIButton to another method, but I couldn't get the syntax for that right. Gave up pretty quick because I assumed that I should be using main (thanks for the advice ;)).

    Download - Currently it's all in ViewController.
  4. macrumors 6502

    Are you using Interface Builder to setup your UI or are you doing everything in code?
  5. macrumors 68020

    Haven't touched Interface Builder, all code (no real reason, just seems easier).
  6. macrumors 6502

    Try this:
    This is assuming your button is named button. Then this:

    But instead of having a NSLog, put in the code for the UIAlertView.
  7. macrumors 68020

    Turns out that's how I was doing if before, but I made a really stupid mistake slightly further on. Works prefect now, thanks for the help!
  8. macrumors 68020

    I have another question: I'd really like so set the background to the same striped background that uses, I know how to do it, I just don't know where to locate the png? Is the image included in the SDK? Just wondering because I see a lot of apps using it.

    I just want to make my app look as Apple-like as possible.
  9. macrumors Pentium


    Use interface builder. ;)

    Seriously, it's much easier for this type of work.
  10. macrumors 68020

    Well, I finally stopped pussying out of using IB (I thought it would be hard to connect up methods with objects) but it turns out you're right, it's incredibly easy to use. Thankfully I found this tutorial which made it even easier.

    Next up: UIPickerView :D
  11. AdrianK, Aug 10, 2011
    Last edited: Aug 11, 2011

    macrumors 68020

    So, I followed a tutorial for UIPickerView and I now understand how it works. Implementing it on a blank 'View based project' was fine, but the project I want to implement it in has a tab bar controller with two views in a single xib.

    Unlike my project which only has an AppDelegate class, 'View based' adds a a View Controller class and a second xib. I can setup UIVP in the view I want and a view controller class for it but I see no way to link the two in interface builder (file's owner would be App Delegate (I assume?) which isn't where it's delegates and data source are).

    Is that the right path or do I need to implement a view in my current view and dump UIVP in the View Controller xib? Or would neither of those work? :p

    EDIT: Rebuilt my app using the 'tab bar application' template, works great!
  12. macrumors 6502

    It's probably a good idea to have a different nib file for each tab of your tab bar. Then you can just set each tab to show the nib associated with it. You can make the association between tabs and nibs in Interface Builder.

Share This Page