-
-
Save akio0911/c8a6352310c9bcfaf915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class TableViewController: UITableViewController { | |
//都道府県名はここから取得 | |
let prefecturalArr = [ | |
"北海道","青森県","岩手県","宮城県","秋田県","山形県", | |
"福島県","茨城県","栃木県","群馬県","埼玉県","千葉県", | |
"東京都","神奈川県","新潟県","富山県","石川県","福井県", | |
"山梨県","長野県","岐阜県","静岡県","愛知県","三重県", | |
"滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県", | |
"鳥取県","島根県","岡山県","広島県","山口県","徳島県", | |
"香川県","愛媛県","高知県","福岡県","佐賀県","長崎県", | |
"熊本県","大分県","宮崎県","鹿児島県","沖縄県" | |
] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Uncomment the following line to preserve selection between presentations | |
// self.clearsSelectionOnViewWillAppear = false | |
// Uncomment the following line to display an Edit button in the navigation bar for this view controller. | |
// self.navigationItem.rightBarButtonItem = self.editButtonItem() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
// MARK: - Table view data source | |
override func numberOfSectionsInTableView(tableView: UITableView) -> Int { | |
// #warning Potentially incomplete method implementation. | |
// Return the number of sections. | |
return 1 | |
} | |
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
// #warning Incomplete method implementation. | |
// Return the number of rows in the section. | |
return prefecturalArr.count | |
} | |
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCellWithIdentifier("PrefecturalCell", forIndexPath: indexPath) as! UITableViewCell | |
// Configure the cell... | |
let prefectureNum = indexPath.row + 1 | |
//都道府県名 | |
let title = cell.viewWithTag(1) as! UILabel | |
title.text = prefecturalArr[prefectureNum-1] | |
//-番目の都道府県です | |
let detail = cell.viewWithTag(2) as! UILabel | |
detail.text = "\(prefectureNum)番目の都道府県です" | |
//番号を渡したら、都道府県名が返ってくる関数 | |
//色をつける箇所 | |
switch prefectureNum % 3 { | |
case 0: | |
//青色 | |
cell.backgroundColor = UIColor(red:0.78, green:0.82, blue:1, alpha:1) | |
case 1: | |
//赤色 | |
cell.backgroundColor = UIColor(red:1, green:0.8, blue:0.79, alpha:1) | |
case 2: | |
//緑色 | |
cell.backgroundColor = UIColor(red:0.85, green:0.96, blue:0.57, alpha:1) | |
default: | |
//実際には使われない | |
cell.backgroundColor = UIColor.whiteColor() | |
} | |
return cell | |
} | |
/* | |
// Override to support conditional editing of the table view. | |
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { | |
// Return NO 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, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { | |
if editingStyle == .Delete { | |
// Delete the row from the data source | |
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .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. | |
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { | |
} | |
*/ | |
/* | |
// Override to support conditional rearranging of the table view. | |
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool { | |
// Return NO if you do not want the item to be re-orderable. | |
return true | |
} | |
*/ | |
/* | |
// MARK: - Navigation | |
// In a storyboard-based application, you will often want to do a little preparation before navigation | |
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { | |
// Get the new view controller using [segue destinationViewController]. | |
// Pass the selected object to the new view controller. | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment