---
title: "iOS Dev (7) Single View App"
author: "prevention"
date: "2013-12-24T00:42:00Z"
tags: []
slug: "ios-dev-7-single-view-app"
draft: false
lastmod: "2014-02-03T16:56:23Z"
id: 2010888
url: "https://prevention.iteye.com/blog/2010888"
---

Mac OS X 10.8

iOS 7 SDK

Xcode5

1\. Command + Shift + N: 创建一个iOS Project，选择Single View Application。Xcode会自动帮助创建一个UIViewController子类及相应的Storyboard。

2\. 拖动一个UIButton控件到Storyboard中。

3\. 按住Control拖动该button到UIViewController子类的头文件(.h)中。

4\. Connection选择Action，Name写showAlert，Type选择id或UIButton，Event选TouchUpInside，Arguments选Sender。

5\. 在UIViewController子类的源文件中的showAlert方法中添加如下代码：

```
    [[[UIAlertView alloc] initWithTitle:@"您好,苍老师"
                                message:@"听说您的新贴转发了 499次"
                               delegate:nil
                      cancelButtonTitle:@"我来帮转1次,你懂的"
                      otherButtonTitles:nil, nil]show];
```

6\. Command + R：运行后点击按钮看效果。