Skip to content

Commit d5a1bac

Browse files
committed
Part 4
1 parent b0e6c62 commit d5a1bac

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

SwiftTutorial/Base.lproj/Main.storyboard

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@
1919
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="0Ds-au-UhU">
2020
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
2121
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
22+
<prototypes>
23+
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="SearchResultCell" textLabel="GZD-IL-v2Z" detailTextLabel="5Re-0H-SJG" style="IBUITableViewCellStyleSubtitle" id="IOy-Jh-366">
24+
<autoresizingMask key="autoresizingMask"/>
25+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="IOy-Jh-366" id="Lwd-Ae-TbU">
26+
<autoresizingMask key="autoresizingMask"/>
27+
<subviews>
28+
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="GZD-IL-v2Z">
29+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
30+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
31+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
32+
<nil key="highlightedColor"/>
33+
<variation key="heightClass=regular-widthClass=compact">
34+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
35+
</variation>
36+
</label>
37+
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Subtitle" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="5Re-0H-SJG">
38+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
39+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
40+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
41+
<nil key="highlightedColor"/>
42+
<variation key="heightClass=regular-widthClass=compact">
43+
<fontDescription key="fontDescription" type="system" pointSize="11"/>
44+
</variation>
45+
</label>
46+
</subviews>
47+
</tableViewCellContentView>
48+
</tableViewCell>
49+
</prototypes>
2250
<variation key="heightClass=regular-widthClass=compact" fixedFrame="YES">
2351
<rect key="frame" x="0.0" y="20" width="320" height="620"/>
2452
</variation>

SwiftTutorial/SearchResultsViewController.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class SearchResultsViewController: UIViewController, UITableViewDataSource, UITa
3030
}
3131

3232
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
33-
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")
33+
let kCellIdentifier: String = "SearchResultCell"
34+
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as UITableViewCell
3435

3536
var rowData: NSDictionary = self.tableData[indexPath.row] as NSDictionary
3637

@@ -52,6 +53,20 @@ class SearchResultsViewController: UIViewController, UITableViewDataSource, UITa
5253
return cell
5354
}
5455

56+
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
57+
// Get the row data for the selected row
58+
var rowData: NSDictionary = self.tableData[indexPath.row] as NSDictionary
59+
60+
var name: String = rowData["trackName"] as String
61+
var formattedPrice: String = rowData["formattedPrice"] as String
62+
63+
var alert: UIAlertView = UIAlertView()
64+
alert.title = name
65+
alert.message = formattedPrice
66+
alert.addButtonWithTitle("Ok")
67+
alert.show()
68+
}
69+
5570
func didReceiveAPIResults(results: NSDictionary) {
5671
var resultsArr: NSArray = results["results"] as NSArray
5772
dispatch_async(dispatch_get_main_queue(), {

0 commit comments

Comments
 (0)