uitextfield uiwebview

Discussion in 'iOS Development' started by deleted account, May 12, 2009.

  1. hello,
    i wanna make an web browser and i have no idea how to make an addressbar and send the text to the uiwebview...
    i make my app with the sample app from gojohnnyboi..

    this is what i have:

    iNet.m:
    Code:
    #import "iNet.h"
    
    @implementation iNet
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
    
    	[UIHardware _setStatusBarHeight:0.0f]; 
    	[self setStatusBarHidden:YES animated:NO]; 
    
    	rect = [ UIHardware fullScreenApplicationContentRect ];
    	rect.origin.x = 0.0f;
    	rect.origin.y = 0.0f;
    
    	window = [ [ UIWindow alloc ] initWithContentRect: rect ];
    	[ window makeKeyAndVisible ];
    
    	mainView = [ [ UIView alloc ] initWithFrame: rect ];
    	[ window setContentView: mainView ];
    
    	navBar = [ [ UINavigationBar alloc ] initWithFrame: CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, 45.0f) ];
    	[ navBar pushNavigationItem: [ [ UINavigationItem alloc ] initWithTitle:@"iNet" ] ];
    	[ navBar showLeftButton:@"test" withStyle:0 rightButton:@"about" withStyle: 0 ];
    	[ navBar setDelegate: self ];
    	[ mainView addSubview: navBar ];
    
    	webView = [ [ UIWebView alloc ] initWithFrame: CGRectMake(rect.origin.x, rect.origin.y + [ navBar bounds ].size.height, rect.size.width, rect.size.height - [ navBar bounds ].size.height) ];
    	urlRequest = [ [ NSURLRequest alloc ] initWithURL: [ NSURL URLWithString: addressBar text ] ];
        [ webView loadRequest: urlRequest ];
    	[ mainView addSubview: webView ];
    }
    
    - (void)dealloc
    {
    	[ window release ];
    	[ mainView release ];
    	[ navBar release ];
    	[ super dealloc ];
    }
    
    - (void)navigationBar:(UINavigationBar*)bar buttonClicked:(int)button
    {
            if( button == 0 ) {
    				UIAlertSheet *sheet = [ [ UIAlertSheet alloc ] init ];
    				[ sheet setTitle: @"..." ];
    				[ sheet setBodyText:@"\nright button" ];
    				[ sheet setDelegate: self ];
    				[ sheet addButtonWithTitle:@"OK" ];
    				[ sheet popupAlertAnimated: YES ];
            } else {
    				UIAlertSheet *sheet = [ [ UIAlertSheet alloc ] init ];
    				[ sheet setTitle: @"..." ];
    				[ sheet setBodyText:@"\nleft button" ];
    				[ sheet setDelegate: self ];
    				[ sheet addButtonWithTitle:@"OK" ];
    				[ sheet popupAlertAnimated: YES ];
    		}
    }
    
    - (void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(int)button
    {
    	[ sheet dismiss ];
    }
    
    @end
    
    iNet.h:
    Code:
    #import <Foundation/Foundation.h>
    #import <CoreFoundation/CoreFoundation.h>
    #import <UIKit/UIKit.h>
    #import <UIKit/UIHardware.h>
    #import <UIKit/UIWindow.h>
    #import <UIKit/UIView.h>
    #import <UIKit/UIWebView.h>
    
    @interface iNet : UIApplication
    {
    	CGRect rect;
    	UIWindow* window;
    	UIView* mainView;
    	UIWebView* webView;
    	NSURLRequest *urlRequest;
    	UINavigationBar* navBar;
    }
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
    - (void)dealloc;
    
    @end
    
    main.m:
    Code:
    #import <UIKit/UIKit.h>
    #import "iNet.h"
    
    int main(int argc, char *argv[])
    {
    	NSAutoreleasePool* pool = [ [ NSAutoreleasePool alloc ] init ];
    	int appReturn = UIApplicationMain(argc, argv, @"iNet", @"iNet");
    	return appReturn;
    	[ pool release ];
    }
    
    makefile:
    Code:
    CC=arm-apple-darwin9-gcc
    LD=$(CC)
    LDFLAGS =	-framework Foundation \
    				-framework UIKit \
    				-framework CoreFoundation \
    				-framework CoreGraphics \
    				-lobjc \
    				-L"/usr/lib" \
    				-F"/System/Library/Frameworks" \
    				-F"/System/Library/PrivateFrameworks" \
    				-bind_at_load
    CFLAGS=-I/var/include
    
    TARGET=Window
    
    all:	$(TARGET)
    
    $(TARGET): main.o iNet.o
    	$(LD) $(LDFLAGS) -o $@ $^
    			ldid -S $(TARGET)
    			chmod 0755 $(TARGET)
    
    %.o:	%.m
    	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
    
    clean:	
    	rm -fr *.o $(TARGET)
    
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    I would find a different HelloWorld application, if I were you. While the example listed below was adequate at some point, it is outdated. Find a HelloWorld to base your application off is organized in a MVC fashion.

    When you have that all set, helping you will become a lot easier. You may even figure it out on your own : )
  3. what does mvc fashion means?
    ------------------double post merged------------------
    ok i've found this:

    Code:
    UITextField *addressbar=[[UITextField alloc] initWithFrame: CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, 90.0f) ];
        addressbar.delegate=self;
        addressbar.textAlignment=UITextAlignmentCenter;
        addressbar.borderStyle=UITextBorderStyleRoundedRect;
        addressbar.placeholder=@"...\n";
        addressbar.autocorrectionType=UITextAutocorrectionTypeNo;
        addressbar.autocapitalizationType=UITextAutocapitalizationTypeNone;
        [mainView addSubview: addressbar];
    
    how can i "connect" the webview with this textfield??
  4. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    MVC is Model *Modal*View Controller, I *think* it's all to do with the way your controllers control objects and so on and so forth....

    Someone please correct me if I am wrong.
  5. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Stop finding code on the web and trying to put it together. Learn the basics and you won't need us. Start by looking on developer.apple.com
  6. the only problem is that i have no mac, no sdk, no hackintosh no interface builder..

    i thought this forum is to help but all answers are not very helpful..
    ------------------double post merged------------------
    i want to connect the webview with the textfield..
    here is what i have:

    i want that the addressbar is below the navbar i don't know if its right but i made the addressbar with 90.0f and the navbar with 45.0f

    Code:
    	navBar = [ [ UINavigationBar alloc ] initWithFrame: CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, 45.0f) ];
    	[ navBar pushNavigationItem: [ [ UINavigationItem alloc ] initWithTitle:@"iNet" ] ];
    	[ navBar showLeftButton:@"test" withStyle:0 rightButton:@"about" withStyle: 0 ];
    	[ navBar setDelegate: self ];
    	[ mainView addSubview: navBar ];
    
    	addressBar =[[UITextField alloc] initWithFrame: CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, 90.0f) ];
    	[ addressBar setDelegate: self ];
        [mainView addSubview: addressBar];
    	
    	webView = [ [ UIWebView alloc ] initWithFrame: CGRectMake(rect.origin.x, rect.origin.y + [ navBar bounds ].size.height, rect.size.width, rect.size.height - [ navBar bounds ].size.height) ];
    	urlRequest = [ [ NSURLRequest alloc ] initWithURL: [ NSURL URLWithString: [addressBar text]] ];
        [ webView loadRequest: urlRequest ];
    	[ mainView addSubview: webView ];
    
  7. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Again, you don't need a mac, or interface builder. You need to find a better hello world to begin from. One that works with view controllers.

    How it would work
    Code:
    /* Where self = yourViewController <UITextFieldDelegate> */
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
    return [webview loadURL:textFeld.text];
    }
    
    
    If you do things properly and find better source code to start from, things will become much easier.
  8. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    Yeah Skylar's tired today......
  9. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    No I'm not, and it's MODEL, not modal.
  10. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    That’s why I put it in asterisks, I guess next time I should get a dictionary.

Share This Page