From 1789247bea400b53763bb3f244d7530a81989d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20B=C3=B8gh?= Date: Mon, 9 Jun 2014 16:26:25 +0200 Subject: [PATCH 1/5] Added a nib based TableViewCell --- .../project.pbxproj | 8 ++++++ .../NibTableViewCell.swift | 13 ++++++++++ .../TableViewController/NibTableViewCell.xib | 26 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift create mode 100644 TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib diff --git a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj index 464381b..7a56e99 100644 --- a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj +++ b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */; }; + 5A3B25381945F8AC00838EF4 /* NibTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */; }; 99BCDCA518008C0000B8E66B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA418008C0000B8E66B /* Foundation.framework */; }; 99BCDCA718008C0000B8E66B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */; }; 99BCDCA918008C0000B8E66B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA818008C0000B8E66B /* UIKit.framework */; }; @@ -35,6 +37,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NibTableViewCell.swift; sourceTree = ""; }; + 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NibTableViewCell.xib; sourceTree = ""; }; 99BCDCA118008C0000B8E66B /* TableViewCellWithAutoLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TableViewCellWithAutoLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; 99BCDCA418008C0000B8E66B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -158,6 +162,8 @@ A7F5DDAB19440B7B008E238B /* Model.swift */, A7C103211943F73D006A9720 /* TableViewCell.swift */, A7F5DDAD194417DC008E238B /* TableViewController.swift */, + 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */, + 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */, ); path = TableViewController; sourceTree = ""; @@ -248,6 +254,7 @@ buildActionMask = 2147483647; files = ( 99BCDCAF18008C0000B8E66B /* InfoPlist.strings in Resources */, + 5A3B25381945F8AC00838EF4 /* NibTableViewCell.xib in Resources */, 99BCDCB718008C0000B8E66B /* Images.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -268,6 +275,7 @@ buildActionMask = 2147483647; files = ( B147F1841867A715002B0C25 /* UIView+AutoLayout.m in Sources */, + 5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */, A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */, A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */, A7F5DDAC19440B7B008E238B /* Model.swift in Sources */, diff --git a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift new file mode 100644 index 0000000..ba90512 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift @@ -0,0 +1,13 @@ +// +// NibTableViewCell.swift +// TableViewCellWithAutoLayout +// +// Created by Morten Bøgh on 09/06/14. +// Copyright (c) 2014 RobotJackalope. All rights reserved. +// + +import UIKit + +class NibTableViewCell: UITableViewCell { + +} diff --git a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib new file mode 100644 index 0000000..9d18fdd --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + From a3cac951654cccc7a9a98414bb6fb9c45d4785e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20B=C3=B8gh?= Date: Mon, 9 Jun 2014 20:57:29 +0200 Subject: [PATCH 2/5] Nib based cell is done and is working as expected. Which is weird because it failed in another project :) --- .../NibTableViewCell.swift | 16 ++++++++- .../TableViewController/NibTableViewCell.xib | 34 +++++++++++++++---- .../TableViewController.swift | 2 ++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift index ba90512..02aca7b 100644 --- a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift @@ -8,6 +8,20 @@ import UIKit -class NibTableViewCell: UITableViewCell { +class NibTableViewCell: UITableViewCell +{ + @IBOutlet var titleLabel : UILabel + @IBOutlet var bodyLabel : UILabel + override func awakeFromNib() + { + super.awakeFromNib() + updateFonts() + } + + func updateFonts() + { + titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline) + bodyLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleCaption2) + } } diff --git a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib index 9d18fdd..a9ecc89 100644 --- a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib +++ b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib @@ -6,21 +6,43 @@ - - + + - + + + + + + + + + + - + + + + + diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index 247bb08..7720290 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -35,7 +35,9 @@ class TableViewController : UITableViewController tableView.allowsSelection = false + // Select either a programatically created cell or a nib-based one. tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) +// tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier) // Self-sizing table view cells in iOS 8 require that the rowHeight property of the table view be set to the constant UITableViewAutomaticDimension tableView.rowHeight = UITableViewAutomaticDimension From 4ca1af27f3e9d900c9134366b45addf3ea5bdd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20B=C3=B8gh?= Date: Mon, 9 Jun 2014 20:57:47 +0200 Subject: [PATCH 3/5] Fixed project settings Xcode warning. --- TableViewCellWithAutoLayout.xcodeproj/project.pbxproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj index 7a56e99..75e4239 100644 --- a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj +++ b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj @@ -222,7 +222,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = RJ; - LastUpgradeCheck = 0500; + LastUpgradeCheck = 0600; ORGANIZATIONNAME = RobotJackalope; TargetAttributes = { 99BCDCBB18008C0000B8E66B = { @@ -325,7 +325,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -365,7 +364,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -433,7 +431,6 @@ 99BCDCD118008C0000B8E66B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TableViewCellWithAutoLayout.app/TableViewCellWithAutoLayout"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", @@ -456,7 +453,6 @@ 99BCDCD218008C0000B8E66B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TableViewCellWithAutoLayout.app/TableViewCellWithAutoLayout"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", From 37124458cfa47f58d503d9ce6d1475b09f0a36bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20B=C3=B8gh?= Date: Mon, 9 Jun 2014 21:15:24 +0200 Subject: [PATCH 4/5] Adjusted the styling --- .../TableViewController/TableViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index 7720290..5517842 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -37,7 +37,7 @@ class TableViewController : UITableViewController // Select either a programatically created cell or a nib-based one. tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) -// tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier) + // tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier) // Self-sizing table view cells in iOS 8 require that the rowHeight property of the table view be set to the constant UITableViewAutomaticDimension tableView.rowHeight = UITableViewAutomaticDimension From 1c648fdc727a7694ec2c7b2e6cabf2364bcba2a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20B=C3=B8gh?= Date: Tue, 10 Jun 2014 19:19:55 +0200 Subject: [PATCH 5/5] Fixed c/p error in a comment. --- .../TableViewController/TableViewCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index 525466e..a32d6a9 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -38,7 +38,7 @@ class TableViewCell: UITableViewCell contentView.addSubview(titleLabel) contentView.addSubview(bodyLabel) - contentView.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.1) // light red + contentView.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.1) // light green updateFonts() }