├── mytableview1.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── brianvoong.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── brianvoong.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── mytableview1.xcscheme │ └── xcschememanagement.plist └── mytableview1 ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj └── LaunchScreen.storyboard ├── Info.plist └── ViewController.swift /mytableview1.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C704F5BF1C7D0FFE00C511FA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C704F5BE1C7D0FFE00C511FA /* AppDelegate.swift */; }; 11 | C704F5C11C7D0FFE00C511FA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C704F5C01C7D0FFE00C511FA /* ViewController.swift */; }; 12 | C704F5C61C7D0FFE00C511FA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C704F5C51C7D0FFE00C511FA /* Assets.xcassets */; }; 13 | C704F5C91C7D0FFE00C511FA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C704F5C71C7D0FFE00C511FA /* LaunchScreen.storyboard */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXFileReference section */ 17 | C704F5BB1C7D0FFE00C511FA /* mytableview1.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = mytableview1.app; sourceTree = BUILT_PRODUCTS_DIR; }; 18 | C704F5BE1C7D0FFE00C511FA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 19 | C704F5C01C7D0FFE00C511FA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 20 | C704F5C51C7D0FFE00C511FA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 21 | C704F5C81C7D0FFE00C511FA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 22 | C704F5CA1C7D0FFE00C511FA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 23 | /* End PBXFileReference section */ 24 | 25 | /* Begin PBXFrameworksBuildPhase section */ 26 | C704F5B81C7D0FFE00C511FA /* Frameworks */ = { 27 | isa = PBXFrameworksBuildPhase; 28 | buildActionMask = 2147483647; 29 | files = ( 30 | ); 31 | runOnlyForDeploymentPostprocessing = 0; 32 | }; 33 | /* End PBXFrameworksBuildPhase section */ 34 | 35 | /* Begin PBXGroup section */ 36 | C704F5B21C7D0FFE00C511FA = { 37 | isa = PBXGroup; 38 | children = ( 39 | C704F5BD1C7D0FFE00C511FA /* mytableview1 */, 40 | C704F5BC1C7D0FFE00C511FA /* Products */, 41 | ); 42 | sourceTree = ""; 43 | }; 44 | C704F5BC1C7D0FFE00C511FA /* Products */ = { 45 | isa = PBXGroup; 46 | children = ( 47 | C704F5BB1C7D0FFE00C511FA /* mytableview1.app */, 48 | ); 49 | name = Products; 50 | sourceTree = ""; 51 | }; 52 | C704F5BD1C7D0FFE00C511FA /* mytableview1 */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | C704F5BE1C7D0FFE00C511FA /* AppDelegate.swift */, 56 | C704F5C01C7D0FFE00C511FA /* ViewController.swift */, 57 | C704F5C51C7D0FFE00C511FA /* Assets.xcassets */, 58 | C704F5C71C7D0FFE00C511FA /* LaunchScreen.storyboard */, 59 | C704F5CA1C7D0FFE00C511FA /* Info.plist */, 60 | ); 61 | path = mytableview1; 62 | sourceTree = ""; 63 | }; 64 | /* End PBXGroup section */ 65 | 66 | /* Begin PBXNativeTarget section */ 67 | C704F5BA1C7D0FFE00C511FA /* mytableview1 */ = { 68 | isa = PBXNativeTarget; 69 | buildConfigurationList = C704F5CD1C7D0FFE00C511FA /* Build configuration list for PBXNativeTarget "mytableview1" */; 70 | buildPhases = ( 71 | C704F5B71C7D0FFE00C511FA /* Sources */, 72 | C704F5B81C7D0FFE00C511FA /* Frameworks */, 73 | C704F5B91C7D0FFE00C511FA /* Resources */, 74 | ); 75 | buildRules = ( 76 | ); 77 | dependencies = ( 78 | ); 79 | name = mytableview1; 80 | productName = mytableview1; 81 | productReference = C704F5BB1C7D0FFE00C511FA /* mytableview1.app */; 82 | productType = "com.apple.product-type.application"; 83 | }; 84 | /* End PBXNativeTarget section */ 85 | 86 | /* Begin PBXProject section */ 87 | C704F5B31C7D0FFE00C511FA /* Project object */ = { 88 | isa = PBXProject; 89 | attributes = { 90 | LastSwiftUpdateCheck = 0720; 91 | LastUpgradeCheck = 0720; 92 | ORGANIZATIONNAME = letsbuildthatapp; 93 | TargetAttributes = { 94 | C704F5BA1C7D0FFE00C511FA = { 95 | CreatedOnToolsVersion = 7.2; 96 | }; 97 | }; 98 | }; 99 | buildConfigurationList = C704F5B61C7D0FFE00C511FA /* Build configuration list for PBXProject "mytableview1" */; 100 | compatibilityVersion = "Xcode 3.2"; 101 | developmentRegion = English; 102 | hasScannedForEncodings = 0; 103 | knownRegions = ( 104 | en, 105 | Base, 106 | ); 107 | mainGroup = C704F5B21C7D0FFE00C511FA; 108 | productRefGroup = C704F5BC1C7D0FFE00C511FA /* Products */; 109 | projectDirPath = ""; 110 | projectRoot = ""; 111 | targets = ( 112 | C704F5BA1C7D0FFE00C511FA /* mytableview1 */, 113 | ); 114 | }; 115 | /* End PBXProject section */ 116 | 117 | /* Begin PBXResourcesBuildPhase section */ 118 | C704F5B91C7D0FFE00C511FA /* Resources */ = { 119 | isa = PBXResourcesBuildPhase; 120 | buildActionMask = 2147483647; 121 | files = ( 122 | C704F5C91C7D0FFE00C511FA /* LaunchScreen.storyboard in Resources */, 123 | C704F5C61C7D0FFE00C511FA /* Assets.xcassets in Resources */, 124 | ); 125 | runOnlyForDeploymentPostprocessing = 0; 126 | }; 127 | /* End PBXResourcesBuildPhase section */ 128 | 129 | /* Begin PBXSourcesBuildPhase section */ 130 | C704F5B71C7D0FFE00C511FA /* Sources */ = { 131 | isa = PBXSourcesBuildPhase; 132 | buildActionMask = 2147483647; 133 | files = ( 134 | C704F5C11C7D0FFE00C511FA /* ViewController.swift in Sources */, 135 | C704F5BF1C7D0FFE00C511FA /* AppDelegate.swift in Sources */, 136 | ); 137 | runOnlyForDeploymentPostprocessing = 0; 138 | }; 139 | /* End PBXSourcesBuildPhase section */ 140 | 141 | /* Begin PBXVariantGroup section */ 142 | C704F5C71C7D0FFE00C511FA /* LaunchScreen.storyboard */ = { 143 | isa = PBXVariantGroup; 144 | children = ( 145 | C704F5C81C7D0FFE00C511FA /* Base */, 146 | ); 147 | name = LaunchScreen.storyboard; 148 | sourceTree = ""; 149 | }; 150 | /* End PBXVariantGroup section */ 151 | 152 | /* Begin XCBuildConfiguration section */ 153 | C704F5CB1C7D0FFE00C511FA /* Debug */ = { 154 | isa = XCBuildConfiguration; 155 | buildSettings = { 156 | ALWAYS_SEARCH_USER_PATHS = NO; 157 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 158 | CLANG_CXX_LIBRARY = "libc++"; 159 | CLANG_ENABLE_MODULES = YES; 160 | CLANG_ENABLE_OBJC_ARC = YES; 161 | CLANG_WARN_BOOL_CONVERSION = YES; 162 | CLANG_WARN_CONSTANT_CONVERSION = YES; 163 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 164 | CLANG_WARN_EMPTY_BODY = YES; 165 | CLANG_WARN_ENUM_CONVERSION = YES; 166 | CLANG_WARN_INT_CONVERSION = YES; 167 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 168 | CLANG_WARN_UNREACHABLE_CODE = YES; 169 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 170 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 171 | COPY_PHASE_STRIP = NO; 172 | DEBUG_INFORMATION_FORMAT = dwarf; 173 | ENABLE_STRICT_OBJC_MSGSEND = YES; 174 | ENABLE_TESTABILITY = YES; 175 | GCC_C_LANGUAGE_STANDARD = gnu99; 176 | GCC_DYNAMIC_NO_PIC = NO; 177 | GCC_NO_COMMON_BLOCKS = YES; 178 | GCC_OPTIMIZATION_LEVEL = 0; 179 | GCC_PREPROCESSOR_DEFINITIONS = ( 180 | "DEBUG=1", 181 | "$(inherited)", 182 | ); 183 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 184 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 185 | GCC_WARN_UNDECLARED_SELECTOR = YES; 186 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 187 | GCC_WARN_UNUSED_FUNCTION = YES; 188 | GCC_WARN_UNUSED_VARIABLE = YES; 189 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 190 | MTL_ENABLE_DEBUG_INFO = YES; 191 | ONLY_ACTIVE_ARCH = YES; 192 | SDKROOT = iphoneos; 193 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 194 | TARGETED_DEVICE_FAMILY = "1,2"; 195 | }; 196 | name = Debug; 197 | }; 198 | C704F5CC1C7D0FFE00C511FA /* Release */ = { 199 | isa = XCBuildConfiguration; 200 | buildSettings = { 201 | ALWAYS_SEARCH_USER_PATHS = NO; 202 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 203 | CLANG_CXX_LIBRARY = "libc++"; 204 | CLANG_ENABLE_MODULES = YES; 205 | CLANG_ENABLE_OBJC_ARC = YES; 206 | CLANG_WARN_BOOL_CONVERSION = YES; 207 | CLANG_WARN_CONSTANT_CONVERSION = YES; 208 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 209 | CLANG_WARN_EMPTY_BODY = YES; 210 | CLANG_WARN_ENUM_CONVERSION = YES; 211 | CLANG_WARN_INT_CONVERSION = YES; 212 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 213 | CLANG_WARN_UNREACHABLE_CODE = YES; 214 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 215 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 216 | COPY_PHASE_STRIP = NO; 217 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 218 | ENABLE_NS_ASSERTIONS = NO; 219 | ENABLE_STRICT_OBJC_MSGSEND = YES; 220 | GCC_C_LANGUAGE_STANDARD = gnu99; 221 | GCC_NO_COMMON_BLOCKS = YES; 222 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 223 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 224 | GCC_WARN_UNDECLARED_SELECTOR = YES; 225 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 226 | GCC_WARN_UNUSED_FUNCTION = YES; 227 | GCC_WARN_UNUSED_VARIABLE = YES; 228 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 229 | MTL_ENABLE_DEBUG_INFO = NO; 230 | SDKROOT = iphoneos; 231 | TARGETED_DEVICE_FAMILY = "1,2"; 232 | VALIDATE_PRODUCT = YES; 233 | }; 234 | name = Release; 235 | }; 236 | C704F5CE1C7D0FFE00C511FA /* Debug */ = { 237 | isa = XCBuildConfiguration; 238 | buildSettings = { 239 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 240 | INFOPLIST_FILE = mytableview1/Info.plist; 241 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 242 | PRODUCT_BUNDLE_IDENTIFIER = com.letsbuildthatapp.mytableview1; 243 | PRODUCT_NAME = "$(TARGET_NAME)"; 244 | }; 245 | name = Debug; 246 | }; 247 | C704F5CF1C7D0FFE00C511FA /* Release */ = { 248 | isa = XCBuildConfiguration; 249 | buildSettings = { 250 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 251 | INFOPLIST_FILE = mytableview1/Info.plist; 252 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 253 | PRODUCT_BUNDLE_IDENTIFIER = com.letsbuildthatapp.mytableview1; 254 | PRODUCT_NAME = "$(TARGET_NAME)"; 255 | }; 256 | name = Release; 257 | }; 258 | /* End XCBuildConfiguration section */ 259 | 260 | /* Begin XCConfigurationList section */ 261 | C704F5B61C7D0FFE00C511FA /* Build configuration list for PBXProject "mytableview1" */ = { 262 | isa = XCConfigurationList; 263 | buildConfigurations = ( 264 | C704F5CB1C7D0FFE00C511FA /* Debug */, 265 | C704F5CC1C7D0FFE00C511FA /* Release */, 266 | ); 267 | defaultConfigurationIsVisible = 0; 268 | defaultConfigurationName = Release; 269 | }; 270 | C704F5CD1C7D0FFE00C511FA /* Build configuration list for PBXNativeTarget "mytableview1" */ = { 271 | isa = XCConfigurationList; 272 | buildConfigurations = ( 273 | C704F5CE1C7D0FFE00C511FA /* Debug */, 274 | C704F5CF1C7D0FFE00C511FA /* Release */, 275 | ); 276 | defaultConfigurationIsVisible = 0; 277 | }; 278 | /* End XCConfigurationList section */ 279 | }; 280 | rootObject = C704F5B31C7D0FFE00C511FA /* Project object */; 281 | } 282 | -------------------------------------------------------------------------------- /mytableview1.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mytableview1.xcodeproj/project.xcworkspace/xcuserdata/brianvoong.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purelyswift/uitableview_row_insertions_programmatically/9628443a5cd3db41cd7ee7a78014582bf12564b3/mytableview1.xcodeproj/project.xcworkspace/xcuserdata/brianvoong.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /mytableview1.xcodeproj/xcuserdata/brianvoong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /mytableview1.xcodeproj/xcuserdata/brianvoong.xcuserdatad/xcschemes/mytableview1.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /mytableview1.xcodeproj/xcuserdata/brianvoong.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | mytableview1.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | C704F5BA1C7D0FFE00C511FA 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /mytableview1/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // mytableview1 4 | // 5 | // Created by Brian Voong on 2/23/16. 6 | // Copyright © 2016 letsbuildthatapp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | 19 | window = UIWindow(frame: UIScreen.mainScreen().bounds) 20 | window?.makeKeyAndVisible() 21 | 22 | let controller = MyTableViewController() 23 | let navigationController = UINavigationController(rootViewController: controller) 24 | window?.rootViewController = navigationController 25 | 26 | 27 | // Override point for customization after application launch. 28 | return true 29 | } 30 | 31 | func applicationWillResignActive(application: UIApplication) { 32 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 33 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 34 | } 35 | 36 | func applicationDidEnterBackground(application: UIApplication) { 37 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 38 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 39 | } 40 | 41 | func applicationWillEnterForeground(application: UIApplication) { 42 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 43 | } 44 | 45 | func applicationDidBecomeActive(application: UIApplication) { 46 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 47 | } 48 | 49 | func applicationWillTerminate(application: UIApplication) { 50 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 51 | } 52 | 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /mytableview1/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /mytableview1/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /mytableview1/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /mytableview1/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // mytableview1 4 | // 5 | // Created by Brian Voong on 2/23/16. 6 | // Copyright © 2016 letsbuildthatapp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MyTableViewController: UITableViewController { 12 | 13 | var items = ["Item 1", "Item 2", "Item 3"] 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | 18 | navigationItem.title = "My TableView" 19 | 20 | tableView.registerClass(MyCell.self, forCellReuseIdentifier: "cellId") 21 | tableView.registerClass(Header.self, forHeaderFooterViewReuseIdentifier: "headerId") 22 | 23 | tableView.sectionHeaderHeight = 50 24 | 25 | navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Insert", style: .Plain, target: self, action: "insert") 26 | 27 | navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Batch Insert", style: .Plain, target: self, action: "insertBatch") 28 | } 29 | 30 | func insertBatch() { 31 | var indexPaths = [NSIndexPath]() 32 | for i in items.count...items.count + 5 { 33 | items.append("Item \(i + 1)") 34 | indexPaths.append(NSIndexPath(forRow: i, inSection: 0)) 35 | } 36 | 37 | var bottomHalfIndexPaths = [NSIndexPath]() 38 | for _ in 0...indexPaths.count / 2 - 1 { 39 | bottomHalfIndexPaths.append(indexPaths.removeLast()) 40 | } 41 | 42 | tableView.beginUpdates() 43 | 44 | tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .Right) 45 | tableView.insertRowsAtIndexPaths(bottomHalfIndexPaths, withRowAnimation: .Left) 46 | 47 | tableView.endUpdates() 48 | } 49 | 50 | func insert() { 51 | items.append("Item \(items.count + 1)") 52 | 53 | let insertionIndexPath = NSIndexPath(forRow: items.count - 1, inSection: 0) 54 | 55 | tableView.insertRowsAtIndexPaths([insertionIndexPath], withRowAnimation: .Automatic) 56 | } 57 | 58 | override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 59 | return items.count 60 | } 61 | 62 | override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 63 | let myCell = tableView.dequeueReusableCellWithIdentifier("cellId", forIndexPath: indexPath) as! MyCell 64 | myCell.nameLabel.text = items[indexPath.row] 65 | myCell.myTableViewController = self 66 | return myCell 67 | } 68 | 69 | override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 70 | return tableView.dequeueReusableHeaderFooterViewWithIdentifier("headerId") 71 | } 72 | 73 | func deleteCell(cell: UITableViewCell) { 74 | if let deletionIndexPath = tableView.indexPathForCell(cell) { 75 | items.removeAtIndex(deletionIndexPath.row) 76 | tableView.deleteRowsAtIndexPaths([deletionIndexPath], withRowAnimation: .Automatic) 77 | } 78 | } 79 | 80 | } 81 | 82 | class Header: UITableViewHeaderFooterView { 83 | 84 | override init(reuseIdentifier: String?) { 85 | super.init(reuseIdentifier: reuseIdentifier) 86 | setupViews() 87 | } 88 | 89 | required init?(coder aDecoder: NSCoder) { 90 | fatalError("init(coder:) has not been implemented") 91 | } 92 | 93 | let nameLabel: UILabel = { 94 | let label = UILabel() 95 | label.text = "My Header" 96 | label.translatesAutoresizingMaskIntoConstraints = false 97 | label.font = UIFont.boldSystemFontOfSize(14) 98 | return label 99 | }() 100 | 101 | func setupViews() { 102 | addSubview(nameLabel) 103 | addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-16-[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel])) 104 | addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel])) 105 | 106 | } 107 | 108 | } 109 | 110 | class MyCell: UITableViewCell { 111 | 112 | var myTableViewController: MyTableViewController? 113 | 114 | override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 115 | super.init(style: style, reuseIdentifier: reuseIdentifier) 116 | setupViews() 117 | } 118 | 119 | required init?(coder aDecoder: NSCoder) { 120 | fatalError("init(coder:) has not been implemented") 121 | } 122 | 123 | let nameLabel: UILabel = { 124 | let label = UILabel() 125 | label.text = "Sample Item" 126 | label.translatesAutoresizingMaskIntoConstraints = false 127 | label.font = UIFont.boldSystemFontOfSize(14) 128 | return label 129 | }() 130 | 131 | let actionButton: UIButton = { 132 | let button = UIButton(type: .System) 133 | button.setTitle("Delete", forState: .Normal) 134 | button.translatesAutoresizingMaskIntoConstraints = false 135 | return button 136 | }() 137 | 138 | func setupViews() { 139 | addSubview(nameLabel) 140 | addSubview(actionButton) 141 | 142 | actionButton.addTarget(self, action: "handleAction", forControlEvents: .TouchUpInside) 143 | 144 | addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-16-[v0]-8-[v1(80)]-8-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel, "v1": actionButton])) 145 | 146 | addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel])) 147 | addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": actionButton])) 148 | 149 | } 150 | 151 | func handleAction() { 152 | myTableViewController?.deleteCell(self) 153 | } 154 | 155 | } 156 | 157 | --------------------------------------------------------------------------------