Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
@邻家的橘猫
Iosswift
提交
a937823c
I
Iosswift
项目概览
@邻家的橘猫
/
Iosswift
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iosswift
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a937823c
编写于
3月 06, 2019
作者:
J
John Hampton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implements Edit and Delete behavior
上级
1ee59103
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
16 deletion
+69
-16
iOSTemplate/Base.lproj/Main.storyboard
iOSTemplate/Base.lproj/Main.storyboard
+5
-1
iOSTemplate/MealTableViewController.swift
iOSTemplate/MealTableViewController.swift
+44
-14
iOSTemplate/MealViewController.swift
iOSTemplate/MealViewController.swift
+20
-1
未找到文件。
iOSTemplate/Base.lproj/Main.storyboard
浏览文件 @
a937823c
...
...
@@ -47,6 +47,7 @@
<outlet
property=
"nameLabel"
destination=
"CD1-k0-BhS"
id=
"a3s-8U-PBl"
/>
<outlet
property=
"photoImageView"
destination=
"Ahk-x7-gIe"
id=
"Ywa-p6-yE8"
/>
<outlet
property=
"ratingControl"
destination=
"mW4-wS-nxh"
id=
"c6i-Bz-Y3a"
/>
<segue
destination=
"BYZ-38-t0r"
kind=
"show"
identifier=
"ShowDetail"
id=
"tWp-7C-aV5"
/>
</connections>
</tableViewCell>
</prototypes>
...
...
@@ -174,10 +175,13 @@
</navigationController>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"GiG-92-fkl"
userLabel=
"First Responder"
sceneMemberID=
"firstResponder"
/>
</objects>
<point
key=
"canvasLocation"
x=
"
860"
y=
"133.5832083958021
"
/>
<point
key=
"canvasLocation"
x=
"
926"
y=
"484
"
/>
</scene>
</scenes>
<resources>
<image
name=
"defaultPhoto"
width=
"1080"
height=
"1080"
/>
</resources>
<inferredMetricsTieBreakers>
<segue
reference=
"tWp-7C-aV5"
/>
</inferredMetricsTieBreakers>
</document>
iOSTemplate/MealTableViewController.swift
浏览文件 @
a937823c
...
...
@@ -6,6 +6,7 @@
//
import
UIKit
import
os
.
log
class
MealTableViewController
:
UITableViewController
{
// MARK: Properties
...
...
@@ -14,6 +15,9 @@ class MealTableViewController: UITableViewController {
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
// Use the edit button item provided by the table view controller.
navigationItem
.
leftBarButtonItem
=
editButtonItem
// Load the sample data.
loadSampleMeals
()
...
...
@@ -46,25 +50,22 @@ class MealTableViewController: UITableViewController {
return
cell
}
/*
// Override to support conditional editing of the table view.
override
func
tableView
(
_
tableView
:
UITableView
,
canEditRowAt
indexPath
:
IndexPath
)
->
Bool
{
// Return false if you do not want the specified item to be editable.
return
true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
override
func
tableView
(
_
tableView
:
UITableView
,
commit
editingStyle
:
UITableViewCell
.
EditingStyle
,
forRowAt
indexPath
:
IndexPath
)
{
if
editingStyle
==
.
delete
{
// Delete the row from the data source
meals
.
remove
(
at
:
indexPath
.
row
)
tableView
.
deleteRows
(
at
:
[
indexPath
],
with
:
.
fade
)
}
else
if
editingStyle
==
.
insert
{
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
...
...
@@ -81,25 +82,54 @@ class MealTableViewController: UITableViewController {
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override
func
prepare
(
for
segue
:
UIStoryboardSegue
,
sender
:
Any
?)
{
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
super
.
prepare
(
for
:
segue
,
sender
:
sender
)
switch
(
segue
.
identifier
??
""
)
{
case
"AddItem"
:
os_log
(
"Adding a new meal."
,
log
:
OSLog
.
default
,
type
:
.
debug
)
case
"ShowDetail"
:
guard
let
mealDetailViewController
=
segue
.
destination
as?
MealViewController
else
{
fatalError
(
"Unexpected destination:
\(
segue
.
destination
)
"
)
}
guard
let
selectedMealCell
=
sender
as?
MealTableViewCell
else
{
fatalError
(
"Unexpected sender:
\(
String
(
describing
:
sender
)
)
"
)
}
guard
let
indexPath
=
tableView
.
indexPath
(
for
:
selectedMealCell
)
else
{
fatalError
(
"The selected cell is not being displayed by the table"
)
}
let
selectedMeal
=
meals
[
indexPath
.
row
]
mealDetailViewController
.
meal
=
selectedMeal
default
:
fatalError
(
"Unexpected Segue Identifier;
\(
String
(
describing
:
segue
.
identifier
)
)
"
)
}
}
*/
// MARK: Actions
@IBAction
func
unwindToMealList
(
sender
:
UIStoryboardSegue
)
{
if
let
sourceViewController
=
sender
.
source
as?
MealViewController
,
let
meal
=
sourceViewController
.
meal
{
// Add a new meal.
let
newIndexPath
=
IndexPath
(
row
:
meals
.
count
,
section
:
0
)
meals
.
append
(
meal
)
tableView
.
insertRows
(
at
:
[
newIndexPath
],
with
:
.
automatic
)
if
let
selectedIndexPath
=
tableView
.
indexPathForSelectedRow
{
// Update an existing meal.
meals
[
selectedIndexPath
.
row
]
=
meal
tableView
.
reloadRows
(
at
:
[
selectedIndexPath
],
with
:
.
none
)
}
else
{
// Add a new meal.
let
newIndexPath
=
IndexPath
(
row
:
meals
.
count
,
section
:
0
)
meals
.
append
(
meal
)
tableView
.
insertRows
(
at
:
[
newIndexPath
],
with
:
.
automatic
)
}
}
}
...
...
iOSTemplate/MealViewController.swift
浏览文件 @
a937823c
...
...
@@ -27,6 +27,14 @@ class MealViewController: UIViewController, UITextFieldDelegate, UIImagePickerCo
// Handle the text field’s user input through delegate callbacks.
nameTextField
.
delegate
=
self
// Set up views if editing an existing Meal.
if
let
meal
=
meal
{
navigationItem
.
title
=
meal
.
name
nameTextField
.
text
=
meal
.
name
photoImageView
.
image
=
meal
.
photo
ratingControl
.
rating
=
meal
.
rating
}
// Enable the Save button only if the text field has a valid Meal name.
updateSaveButtonState
()
}
...
...
@@ -72,7 +80,18 @@ class MealViewController: UIViewController, UITextFieldDelegate, UIImagePickerCo
// MARK: Navigation
@IBAction
func
cancel
(
_
sender
:
UIBarButtonItem
)
{
dismiss
(
animated
:
true
,
completion
:
nil
)
// Depending on style of presentation (modal or push presentation), this view controller needs to be dismissed in two different ways.
let
isPresentingInAddMealMode
=
presentingViewController
is
UINavigationController
if
isPresentingInAddMealMode
{
dismiss
(
animated
:
true
,
completion
:
nil
)
}
else
if
let
owningNavigationController
=
navigationController
{
owningNavigationController
.
popViewController
(
animated
:
true
)
}
else
{
fatalError
(
"The MealViewController is not inside a navigation controller."
)
}
}
// This method lets you configure a view controller before it's presented.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录