@@ -4,38 +4,31 @@ import UIKit
4
4
5
5
class ViewController : UIViewController {
6
6
@IBOutlet var tabbar : UITabBar !
7
- var items = [ UITabBarItem] ( )
7
+ var items : [ UITabBarItem ] = {
8
+ Array ( 1 ..< 8 ) . map {
9
+ UITabBarItem (
10
+ tabBarSystemItem: UITabBarSystemItem ( rawValue: $0) !,
11
+ tag: $0)
12
+ }
13
+ } ( )
8
14
9
15
override func viewDidLoad( ) {
10
16
super. viewDidLoad ( )
11
-
12
- for ix in 1 ..< 8 {
13
- self . items. append (
14
- UITabBarItem (
15
- tabBarSystemItem: UITabBarSystemItem ( ix) , tag: ix
16
- )
17
- )
18
- }
19
- var arr = Array ( self . items [ 0 ..< 4 ] )
20
- arr. append (
21
- UITabBarItem ( tabBarSystemItem: . More, tag: 0 )
22
- )
23
- self . tabbar. items = arr
24
- self . tabbar. selectedItem = self . tabbar. items [ 0 ] as UITabBarItem
17
+ self . tabbar. items = Array ( self . items [ 0 ..< 4 ] ) + [ UITabBarItem ( tabBarSystemItem: . More, tag: 0 ) ]
18
+ self . tabbar. selectedItem = self . tabbar. items![ 0 ] as? UITabBarItem
25
19
}
26
20
}
27
21
28
22
extension ViewController : UITabBarDelegate {
29
- func tabBar( tabBar: UITabBar ! , didSelectItem item: UITabBarItem ! ) {
23
+ func tabBar( tabBar: UITabBar , didSelectItem item: UITabBarItem ! ) {
30
24
println ( " did select item with tag \( item. tag) " )
31
25
if item. tag == 0 {
32
26
// More button
33
27
tabBar. selectedItem = nil
34
28
tabBar. beginCustomizingItems ( self . items)
35
29
}
36
30
}
37
-
38
- func tabBar( tabBar: UITabBar ! , didEndCustomizingItems items: [ AnyObject ] ! , changed: Bool ) {
39
- self . tabbar. selectedItem = self . tabbar. items [ 0 ] as UITabBarItem
31
+ func tabBar( tabBar: UITabBar , didEndCustomizingItems items: [ AnyObject ] , changed: Bool ) {
32
+ self . tabbar. selectedItem = self . tabbar. items![ 0 ] as? UITabBarItem
40
33
}
41
34
}
0 commit comments