-2

I'm trying to make an app for iphone which will send a tcp connection to a specified urf (or web application). I want the button to firstly give an allert before sending. I wrote this code for this:

-(IBAction)tiklandi:(id)sender{
NSString *buton1 = [sender titleForState:UIControlStateNormal];
NSString *uyariText = [[NSString alloc] initWithFormat:@"istek gönderiliyor!"];
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Sunucuya Gönderildi" message:uyariText delegate:nil
    cancelButtonTitle:@"işlemi iptal ettiniz!"
                                    otherButtonTitles: nil];
[alert show];
//[alert release];

but I couldn't use any url methods in my code.

My second question is, I can't see my Interface builder in Developer directory and also in project navigator of Xcode I can't see folders, all the classes come mixed between each other. I use Xcode 4.2, and I'm new with all these, can anyone please help?


I tried the listed solutions but I dont know how to interact my view controller files and .xib file. Here is my view controller .h file:

@interface ViewController : UIViewController


@property (nonatomic, retain) NSURLRequest *url;
@property (nonatomic,retain) UIButton *buton;


-(IBAction)fonksiyon:(id)sender;
@end

and this is my implementation file (of view control .. .m)

#import "ViewController.h"

@implementation ViewController

@synthesize buton;
@synthesize url;



-(IBAction)fonksiyon:(id)sender{

    NSString *buton= [sender titleForState:UIControlStateNormal];
    NSURL *url= [sender url];
    NSString *uyariText= [[NSString alloc] initWithFormat:@"gönderiliyor!"];
    UIAlertView *alertView= [[UIAlertView alloc]initWithTitle:@"Sunucuya Gönderildi" 
                                                  message:uyariText
                                                 delegate:self
                                        cancelButtonTitle:@"işlemi iptal ettiniz!" 
                                        otherButtonTitles:@"Server'a Git!", nil];

    - (NSURL)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
        if (buttonIndex != [alertView cancelButtonIndex]) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://192.168.69.290/cgi-bin/ipad.pl";nil]];
        }

    }

}

The problem is that I can not make a relation between .xib file and the other ones via File's Owner. As I understand, when I drag from file's owner I should see my function (here called fonksiyon) too. Can anyone help?

Michael J. Barber
  • 24,518
  • 9
  • 68
  • 88
il_old
  • 21
  • 3

2 Answers2

0

set the delegate to self when you create the UIAlertView and implement one of the UIAlertViewDelegate methods. Of course if you want to provide the option to cancel you need a "otherButtonTitle"

UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Sunucuya Gönderildi" 
                                              message:uyariText
                                             delegate:self
                                    cancelButtonTitle:@"işlemi iptal ettiniz!" 
                                    otherButtonTitles:@"Go to website", nil];

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex != [alertView cancelButtonIndex]) {
        // open url in external safari
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://foo.bar"]];
        // EDIT: I might have misunderstood your question. 
        // you should read about NSURLConnection and put that code here.
    }
}

my second question is, i cant see my Interface builder in Developer directory

Interface Builder is no longer an extra application. It is now built-in to Xcode. You don't need to launch it, just select the xib file in Xcode.

and also in project navigator of Xcode i can't see folders, all the classes come mixed between each other.

Select the files you want to group, do a secondary click and select "New Group from Selection". You are responsible for grouping your files. When you have an existing group just drag&drop your files there.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
  • thank you very very much. i think since i'm in very beggining of xcode-and objective c- i cant't explain my matter in a technical manner. now the only problem is implementing the NSURLConnection class, i will read a little about that. – il_old Dec 05 '11 at 09:25
0
  1. You have to implement the delegate protocol for UIAlert to handle user's response. Then you'll be able to open the URL you want.

  2. Interface Builder is no longer a separate application (since XCode v4)> Just open a XIB/NIB file in XC.

  3. To open a URL in Safari mobile check this question: How can I launch Safari from an iPhone app?

  4. If you want to open an URL inside your app you need to build your own UIWebView: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/

Community
  • 1
  • 1
Sylvain G.
  • 508
  • 2
  • 9
  • thank you for your reply but i cant make relations between the .xib file i created and my app. And i dont want to open any result in my application, it will include a commend and when the button clicked it will send that commend to server-for now it is enough for me just to interact with url. can you please again help? – il_old Dec 05 '11 at 09:13
  • To ensure your app knows about the XIB file you have to: 1. assign it to the target (in the inspector, on the right). This shall be done automatically. 2. make sure that you XIB is owned by your view controller (Set file owner to your controller's class). The controller must be loaded from the XIB file. Check the MVC tutorials on Apple's documentation. for more details. – Sylvain G. Dec 06 '11 at 10:09