PDA

View Full Version : Newbie question




AdrianK
Aug 6, 2011, 01:44 PM
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
Aug 6, 2011, 02:18 PM
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
Aug 6, 2011, 02:44 PM
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 (http://cl.ly/3S1I1s1c231Z0Z091G0p) - Currently it's all in ViewController.

Shawnpk
Aug 6, 2011, 05:59 PM
Are you using Interface Builder to setup your UI or are you doing everything in code?

AdrianK
Aug 6, 2011, 06:43 PM
Are you using Interface Builder to setup your UI or are you doing everything in code?

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

Shawnpk
Aug 6, 2011, 09:22 PM
Haven't touched Interface Builder, all code (no real reason, just seems easier).

Try this:
[button addTarget:self action:@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
Aug 7, 2011, 04:54 AM
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
Aug 8, 2011, 08:47 AM
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
Aug 8, 2011, 08:50 AM
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
Aug 8, 2011, 03:13 PM
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 (http://oleb.net/blog/2011/06/creating-outlets-and-actions-via-drag-and-drop-in-xcode-4/) tutorial which made it even easier.

Next up: UIPickerView :D

AdrianK
Aug 10, 2011, 12:02 PM
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!

Shawnpk
Aug 10, 2011, 12:10 PM
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.