iphone开发周记1,interfacebuilder的使用

来源:互联网 发布:越狱工具for mac 编辑:程序博客网 时间:2024/03/28 21:46

经过不懈的努力,我终于在自己的神州A550 i5d上成功地装上了mac10.6.2。折腾了两天,找到了声卡驱动,网卡驱动等。然后修改dsdt地bios信息成功让mac识别了显卡。现在基本完美。。。先秀一下图

言归正传,通过一个星期的学习,我掌握了objective-c的一些基本语法。下面介绍一下如何用interfacebuilder加上简单的objectie-c语言写一个iPhone上的浏览器。

先简单介绍一下objective-c,它是c语言的超集。里面可以使用很多c的东西,如函数,指针之类的,又有许多面向对象的思想。

它与c(++)的不同:

c的函数申明:

(返回值类型)函数名(形参列表);

objective-c的函数申明:

(+/-(说实话我暂时还不清楚,但一般是“-”))(返回类型)函数名:形参列表;

c++的类申明:

class A:XXX

{

public:XXX;

....

}

objective-c类的声明:

@interface XXX:NSObject

{

....(成员变量声明)

}

...(成员函数声明)

@end

@implementation XXX

....(方法代码)

@end

c++类的方法调用

XXX.XXXf;

objective-c:

[XXX XXXf];

....这为个人归类;便于记忆,有很多纰漏。

 

下面介绍一下如何使用ib(interface builder),并建立一个iphone上的浏览器。

先建立一个iphone的工程。

在组织资源的组中找到XXXviewcontrol.xib(XXX为工程的名字)

双击便打开了ib,然后点tool,打开library;先加入一个webview控件,然后加入你想加的控件,

比如加入go按钮,reload按钮,gofowards按钮,goback按钮等。

然后再在xcode中加入下代码。

再XXXviewcontroller.h中加入

#import <UIKit/UIKit.h>

@interface webViewController : UIViewController {
    IBOutlet UITextField *newurl;
    IBOutlet UIWebView *myweb;

}
-(IBAction)click;


@end

在XXXviewcontroller.m中加入:

#import "webViewController.h"

@implementation webViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}
- (void)click{
    [newurl resignFirstResponder];
    NSURL *url =[[NSURL alloc] initWithString:newurl.text];
    NSURLRequest *request=[[NSURLRequest alloc] initWithURL:url];
    [myweb loadRequest:request];
    [request release];
    [url release];
   
}


@end

编译保存后,再回到IB界面,点窗口中webveiw控件属性中就可以将这个控件的名字选为mywebview,和我们定义的mywebview绑定起来了。

同样地将TextField与newurl连接起来。

然后将click事件与go按钮连接起来。

再将gofowards按钮与webview的goforwards事件连接起来,同理将其他按钮与你希望按钮按下后发生的事件连接起来。保存

这样你的iphone浏览器就做好了。

这只是简单地介绍了一下xcode的使用,不太会写技术blog。。。。。