Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

mission3 #108

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aritaku/iOS-client/My1DayApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
3ABA190A1B062C5B00C21087 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABA19091B062C5B00C21087 /* Message.swift */; };
3ABA190C1B0633E800C21087 /* ImageHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABA190B1B0633E800C21087 /* ImageHelper.swift */; };
3AF957B81B05067F00106729 /* logo.png in Resources */ = {isa = PBXBuildFile; fileRef = 3AF957B71B05067F00106729 /* logo.png */; };
5DBF87CA1B19AACD00AD9A5F /* DeleteButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DBF87C91B19AACD00AD9A5F /* DeleteButton.swift */; };
CE8066ED1ADDF6E3003A2D22 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE8066EC1ADDF6E3003A2D22 /* AppDelegate.swift */; };
CE8066F21ADDF6E3003A2D22 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE8066F01ADDF6E3003A2D22 /* Main.storyboard */; };
CE8066F41ADDF6E3003A2D22 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE8066F31ADDF6E3003A2D22 /* Images.xcassets */; };
Expand Down Expand Up @@ -52,6 +53,7 @@
3ABA19091B062C5B00C21087 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
3ABA190B1B0633E800C21087 /* ImageHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageHelper.swift; sourceTree = "<group>"; };
3AF957B71B05067F00106729 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = "<group>"; };
5DBF87C91B19AACD00AD9A5F /* DeleteButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeleteButton.swift; path = My1DayApp/DeleteButton.swift; sourceTree = "<group>"; };
CE8066E71ADDF6E3003A2D22 /* My1DayApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = My1DayApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
CE8066EB1ADDF6E3003A2D22 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CE8066EC1ADDF6E3003A2D22 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -110,6 +112,7 @@
CE8066DE1ADDF6E3003A2D22 = {
isa = PBXGroup;
children = (
5DBF87C91B19AACD00AD9A5F /* DeleteButton.swift */,
CE8066E91ADDF6E3003A2D22 /* My1DayApp */,
CE8066FF1ADDF6E3003A2D22 /* My1DayAppTests */,
CE8066E81ADDF6E3003A2D22 /* Products */,
Expand Down Expand Up @@ -275,6 +278,7 @@
3A7CDC921AEA88B5000FBC23 /* MessageTableViewCell.swift in Sources */,
3A7CDC901AEA7B12000FBC23 /* MessageTableViewController.swift in Sources */,
3ABA190A1B062C5B00C21087 /* Message.swift in Sources */,
5DBF87CA1B19AACD00AD9A5F /* DeleteButton.swift in Sources */,
3A877DA01B00E9D0002B726B /* APIRequest.swift in Sources */,
CE8066ED1ADDF6E3003A2D22 /* AppDelegate.swift in Sources */,
3ABA190C1B0633E800C21087 /* ImageHelper.swift in Sources */,
Expand Down
20 changes: 20 additions & 0 deletions aritaku/iOS-client/My1DayApp/APIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,28 @@ class APIRequest {
let task: NSURLSessionDataTask = session.dataTaskWithRequest(request, completionHandler: completionHandler)
task.resume()
}

//deleteするmethot
class func deleteMessage(id: Int, completionHandler: ((NSData!, NSURLResponse!, NSError!) -> Void)?) {
let request: NSMutableURLRequest = NSMutableURLRequest(URL: NSURL(string: APIRequest.baseURLString + Endpoint.Messages.rawValue)!)
request.HTTPMethod = "POST"
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")

var error: NSError?
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(["id":id], options: NSJSONWritingOptions.allZeros, error: &error)

if error != nil{
println(error)
return
}

let session: NSURLSession = NSURLSession.sharedSession()
let task: NSURLSessionDataTask = session.dataTaskWithRequest(request, completionHandler: completionHandler)
task.resume()
}

enum Endpoint: String {
case Messages = "messages"
case Delete = "delete"
}
}
34 changes: 27 additions & 7 deletions aritaku/iOS-client/My1DayApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7531" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="pQh-c6-WXV">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="pQh-c6-WXV">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
</dependencies>
<scenes>
<!--Root View Controller-->
<scene sceneID="IDU-m6-Lyb">
<objects>
<tableViewController id="JOZ-JG-2Hn" customClass="MessageTableViewController" customModule="My1DayApp" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="70" sectionHeaderHeight="22" sectionFooterHeight="22" id="Aeu-LH-nIF">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="105" sectionHeaderHeight="22" sectionFooterHeight="22" id="Aeu-LH-nIF">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.96078431369999995" green="0.96078431369999995" blue="0.96078431369999995" alpha="1" colorSpace="calibratedRGB"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="MessageCell" rowHeight="70" id="6IH-Ch-NUR" customClass="MessageTableViewCell" customModule="My1DayApp" customModuleProvider="target">
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="MessageCell" rowHeight="105" id="6IH-Ch-NUR" customClass="MessageTableViewCell" customModule="My1DayApp" customModuleProvider="target">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="6IH-Ch-NUR" id="Ucl-m3-jPt">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rB6-1N-vrf">
<rect key="frame" x="5" y="5" width="60" height="60"/>
<rect key="frame" x="8" y="35" width="60" height="60"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="作成日時" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zFQ-xF-FwS">
<rect key="frame" x="78" y="64" width="234" height="31"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="メッセージ" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="RPy-Rd-KYT">
<rect key="frame" x="78" y="13" width="234" height="21"/>
<rect key="frame" x="76" y="35" width="234" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="UserName" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jJk-RM-l69">
<rect key="frame" x="8" y="0.0" width="304" height="27"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="date" destination="zFQ-xF-FwS" id="bKB-Mp-gMy"/>
<outlet property="iconImageView" destination="rB6-1N-vrf" id="qKn-zx-yfW"/>
<outlet property="messageLabel" destination="RPy-Rd-KYT" id="6X3-KT-Lfn"/>
<outlet property="username" destination="jJk-RM-l69" id="feC-m4-uVK"/>
</connections>
</tableViewCell>
</prototypes>
Expand Down Expand Up @@ -71,14 +85,19 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="200"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Lhg-Dc-uxP">
<rect key="frame" x="74" y="67" width="246" height="128"/>
<rect key="frame" x="74" y="67" width="246" height="63"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="logo.png" translatesAutoresizingMaskIntoConstraints="NO" id="71b-O0-MO6">
<rect key="frame" x="3" y="67" width="63" height="63"/>
</imageView>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Dcq-HK-SX4">
<rect key="frame" x="8" y="162" width="304" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand Down Expand Up @@ -120,6 +139,7 @@
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
<connections>
<outlet property="messageTextView" destination="Lhg-Dc-uxP" id="Y5X-Cg-E1p"/>
<outlet property="userName" destination="Dcq-HK-SX4" id="X4r-YF-7Kp"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="P5w-qQ-jfU" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
13 changes: 13 additions & 0 deletions aritaku/iOS-client/My1DayApp/DeleteButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DeleteButton.swift
// My1DayApp
//
// Created by 辻林大揮 on 2015/05/30.
// Copyright (c) 2015年 VOYAGE GROUP, inc. All rights reserved.
//

import UIKit

class DeleteButton: UIButton {

}
11 changes: 10 additions & 1 deletion aritaku/iOS-client/My1DayApp/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ import UIKit
class Message {
let body: String!
let icon: UIImage?
let date: String!
let userName: String!
// Mission1-1. created_at 用のインスタンス変数を追加
let id:Int!

init?(dictionary: [String: AnyObject]) {
// Mission1-1 Dictionary から key:created_at の値を取得
if let body: String = dictionary["body"] as? String, let icon: String = dictionary["icon"] as? String {
if let body: String = dictionary["body"] as? String, let icon: String = dictionary["icon"] as? String, let date: String = dictionary["created_at"] as? String, let userName: String = dictionary["username"] as? String {
self.body = body
self.icon = ImageHelper.imageWithBase64EncodedString(icon)
self.date = date
self.userName = userName
self.id = dictionary["id"] as? Int
// Mission1-1 Dictionary から取得した値を created_at 用のインスタンス変数に追加
} else {
self.body = nil
self.icon = nil
self.date = nil
self.userName = nil
// Mission1-1 インスタンス変数を nil で初期化
self.id = nil
return nil
}
}
Expand Down
9 changes: 9 additions & 0 deletions aritaku/iOS-client/My1DayApp/MessageTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ import UIKit
class MessageTableViewCell: UITableViewCell {
@IBOutlet weak private var iconImageView: UIImageView!
@IBOutlet weak private var messageLabel: UILabel!
@IBOutlet weak private var username: UILabel!
@IBOutlet weak private var date: UILabel!
// Mission1-1 UILabel のインスタンス変数を追加
var id:Int!

override func prepareForReuse() {
self.iconImageView.image = nil
self.messageLabel.text = nil
self.username.text = nil
self.date.text = nil
// Mission1-1 UILabel のインスタンス変数を初期化
self.id = nil
}

func setupComponentsWithMessage(message: Message) {
self.iconImageView.image = message.icon
self.messageLabel.text = message.body
self.username.text = message.userName
self.date.text = message.date
// Mission1-1 UILabel のインスタンス変数に created_at の値を代入
self.id = message.id
}
}
62 changes: 62 additions & 0 deletions aritaku/iOS-client/My1DayApp/MessageTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,66 @@ class MessageTableViewController: UITableViewController, PostViewControllerDelag
self.reloadMessageTableView()
}
}


/*
Editableの状態にする.
*/
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}

/*
特定の行のボタン操作を有効にする.
*/
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}

/*
Buttonを拡張する.
*/
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {


// Deleteボタン.
var deleteButton: UITableViewRowAction = UITableViewRowAction(style: .Normal, title: "Delete") { (action, index) -> Void in

tableView.editing = false


//ここがボタン押された時

var id:Int!
var cell = tableView.cellForRowAtIndexPath(indexPath) as! MessageTableViewCell
id = cell.id
println(id)

APIRequest.deleteMessage(id) {
[weak self] (data, response, error) -> Void in


if error != nil {
// TODO: エラー処理
println(error)
return
}

var decodeError: NSError?
let responseBody: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.allZeros, error: &decodeError)
if decodeError != nil{
println(decodeError)
return
}


}



}
deleteButton.backgroundColor = UIColor.redColor()

return [deleteButton]
}

}
10 changes: 9 additions & 1 deletion aritaku/iOS-client/My1DayApp/PostViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ protocol PostViewControllerDelagate : NSObjectProtocol {

class PostViewController: UIViewController {
@IBOutlet weak private var messageTextView: UITextView!
@IBOutlet weak private var userName: UITextField!
weak var delegate: PostViewControllerDelagate?
// Mission1-2 Storyboard から UITextField のインスタンス変数を追加

override func viewDidLoad() {
super.viewDidLoad()
self.messageTextView.becomeFirstResponder()
self.userName.placeholder = "ユーザー名"
}

// MARK: - IBAction
Expand All @@ -33,10 +35,11 @@ class PostViewController: UIViewController {
self.messageTextView.resignFirstResponder()

let message: String = self.messageTextView.text ?? ""
let username: String = self.userName.text ?? ""
// Mission1-2 UITextField のインスタンス変数から値を取得

// Mission1-2 posetMessage の第2引数に 任意の値を渡す
APIRequest.postMessage(message, username: "名前はまだない") {
APIRequest.postMessage(message, username: username) {
[weak self] (data, response, error) -> Void in

self?.delegate?.postViewController(self!, didTouchUpCloseButton: sender)
Expand All @@ -56,4 +59,9 @@ class PostViewController: UIViewController {
}

}





}
Loading