Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AdrianK

macrumors 68020
Original poster
Feb 19, 2011
2,230
2
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.
 

ViviUO

macrumors 6502
Jul 4, 2009
307
22
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?
 

AdrianK

macrumors 68020
Original poster
Feb 19, 2011
2,230
2
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?

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.
 
Last edited:

Shawnpk

macrumors 6502
Jan 13, 2011
350
0
Los Angeles, CA
Haven't touched Interface Builder, all code (no real reason, just seems easier).

Try this:
[button addTarget:self action:mad:selector(buttonPressed)
forControlEvents:UIControlEventTouchUpInside];

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

-(void)buttonPressed {
* NSLog(@"Button Pressed!");

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

AdrianK

macrumors 68020
Original poster
Feb 19, 2011
2,230
2
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.

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!
 

AdrianK

macrumors 68020
Original poster
Feb 19, 2011
2,230
2
I have another question: I'd really like so set the background to the same striped background that Preferences.app 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.
 

KnightWRX

macrumors Pentium
Jan 28, 2009
15,046
4
Quebec, Canada
I have another question: I'd really like so set the background to the same striped background that Preferences.app 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.

Use interface builder. ;)

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

AdrianK

macrumors 68020
Original poster
Feb 19, 2011
2,230
2
Use interface builder. ;)

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

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
 

AdrianK

macrumors 68020
Original poster
Feb 19, 2011
2,230
2
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!
 
Last edited:

Shawnpk

macrumors 6502
Jan 13, 2011
350
0
Los Angeles, CA
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.