在 Xcode5 的 ios 開發中
Apple 拿掉了 Use Stroyboards 與 Use Automatic Reference Counting 的選項
對於不習慣使用 Storyboard 與 Arc 的人造成一定的困擾(我自己...)
這邊介紹怎麼在 Xcode5 下不使用 Storyboards 與 Arc 來開發
一樣開啟 Xcode5 建立一個專案
選擇 Empty Application
建立完成後大該長這個樣
接著先至 Project 的 Build Settings 將 ARC 的使用改為 no
再來就至專案下建立熟悉的 ViewController
習慣使用 xib 開發的記得要將 xib 的選項打勾
因為本人不習慣使用 xib 所以就沒勾了
Creat 後會長這樣
開始寫 code
AppDelegate.h
#import "MainViewController.h" //import viewcontroller @interface AppDelegate : UIResponder<UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (retain, nonatomic) MainViewController *viewcontroller_main; //define viewcontroller @end
AppDelegate.m 的部分要注意將 ARC 設為 no 之後就可以加上 autorelease 了
AppDelegate.m
-(void)dealloc{
[_viewcontroller_main release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewcontroller_main = [[MainViewController alloc]initWithNibName:nil bundle:nil];
[self.window setRootViewController:self.viewcontroller_main];
[self.viewcontroller_main release];
[self.window makeKeyAndVisible];
return YES;
}
MainViewController.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self.view setBackgroundColor:[UIColor whiteColor]];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIAlertView *alertview = [[UIAlertView alloc]initWithTitle:@"hello world" message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alertview show];
[alertview release];
}
最後模擬器下的結果應該會像這樣










