PIXNET Logo登入

Will的部落格

跳到主文

Will程式語言學習筆記

部落格全站分類:數位生活

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 8月 02 週日 201516:02
  • iOS - UITableView條列式清單

創建專案時選擇Master-Detail Application,
並改寫MaterViewController.m檔,
程式碼如下:
//
// MasterViewController.m
// tableView
//
// Created by HungWei on 8/2/15.
// Copyright (c) 2015 HungWei. All rights reserved.
//

#import "MasterViewController.h"
#import "DetailViewController.h"

@interface MasterViewController ()

@property NSMutableArray *objects;
@end

@implementation MasterViewController

- (void)awakeFromNib {
[super awakeFromNib];
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;

dataArray = [[NSMutableArray alloc]initWithObjects: //陣列儲存欲顯示之資料
@{@"Title": @"banana", @"ImageFileName": @"banana.png"},
@{@"Title": @"tomato", @"ImageFileName": @"tomato.png"},
@{@"Title": @"guava", @"ImageFileName": @"guava.png"}, nil];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)insertNewObject:(id)sender {
if (!self.objects) {
self.objects = [[NSMutableArray alloc] init];
}
[self.objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

#pragma mark - Segues

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = self.objects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}

#pragma mark - Table View

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; //只顯示一個section
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [dataArray count]; //回傳列數
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

NSDate *object = self.objects[indexPath.row]; //呈現物件資料
cell.textLabel.text = [[dataArray objectAtIndex:indexPath.row]
objectForKey:@"Title"];
return cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}

@end

(繼續閱讀...)
文章標籤

Will 發表在 痞客邦 留言(0) 人氣(474)

  • 個人分類:初階UI設計 - 顯示型元件
▲top
  • 8月 01 週六 201522:29
  • iOS - UIScrollView瀏覽大圖

UIScrollView可幫助我們在手機顯示的小畫面中瀏覽大圖,
將大圖複製進xcode後,在套入以下程式碼即可執行。
viewController.h
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIScrollViewDelegate>
{
UIImageView *imageView;
UILabel *scaleRatioLabel;
}

@end
(繼續閱讀...)
文章標籤

Will 發表在 痞客邦 留言(0) 人氣(205)

  • 個人分類:初階UI設計 - 顯示型元件
▲top
  • 6月 28 週日 201522:44
  • iOS - UIImageView實現Animation(2)

此方法是設定一個NSArray儲存動畫所需圖片,
再取出array的index值,
在採用NSTimer或迴圈操作index值來播放動畫,
取出NSArray之index可參考以下語法。
(繼續閱讀...)
文章標籤

Will 發表在 痞客邦 留言(0) 人氣(38)

  • 個人分類:初階UI設計 - 顯示型元件
▲top
  • 5月 18 週一 201500:24
  • iOS - UIImageView實現縮放(scale)特效動畫

UIImageView實現縮放特效動畫
 
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *animationImages = @[
[UIImage imageNamed:@"1.jpg"],
[UIImage imageNamed:@"2.jpg"],
[UIImage imageNamed:@"3.jpg"],
[UIImage imageNamed:@"4.jpg"]
];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 300)];
imageView.animationImages = animationImages ;
imageView.animationRepeatCount = 0;
imageView.animationDuration= 12.0;
[imageView startAnimating];
[self.view addSubview:imageView];

// 當圖片改變時呼叫執行動畫的 method => scaleView:
[[NSTimer scheduledTimerWithTimeInterval:12.0/animationImages.count
target:self
selector:@selector(scaleView:)
userInfo:@{
@"view": imageView
}
repeats:YES] fire];
}

- (void)scaleView:(NSTimer *)timer {
UIImageView *view = [timer.userInfo objectForKey:@"view"];
view.frame = CGRectMake(150, 150, 20, 20);
CGPoint center = view.center;
[UIView animateWithDuration: 1.0f
animations:^{
view.frame = CGRectMake(10, 10, 300, 300);
view.center = center;
}];

}
@end
(繼續閱讀...)
文章標籤

Will 發表在 痞客邦 留言(0) 人氣(549)

  • 個人分類:初階UI設計 - 顯示型元件
▲top
  • 3月 21 週六 201512:42
  • iOS - UIImageView實現Animation

此範例先將動畫要用之圖片複製近xcode中,
接著使用一個array並存放圖片,
之後創建一個imageView物件顯示動畫窗格,
再透過[imageView startAnimating]此方法播放動畫, 程式碼如下
(繼續閱讀...)
文章標籤

Will 發表在 痞客邦 留言(0) 人氣(1,119)

  • 個人分類:初階UI設計 - 顯示型元件
▲top
1

個人資訊

Will
暱稱:
Will
分類:
數位生活
好友:
累積中
地區:

熱門文章

  • (27,188)Linux - cd指令(切換工作目錄)
  • (7,431)51. 英文片語 - better safe than sorry
  • (6,171)50. 英文片語 - be that as it may
  • (4,990)9. 英文片語 - lost one's train of thought
  • (4,597)38. 英文片語 - butt head with someone
  • (4,348)41. 英文片語 - have my heart set on (something)
  • (1,242)22. 英文片語 - get off one's back
  • (667)33. 英文片語 - be packed like sardines
  • (605)55. 英文片語 - stick to
  • (590)24. 英文片語 - out of one's element

文章分類

toggle SWIFT (2)
  • 網路服務與應用 (1)
  • 多媒體應用 (2)
toggle appleWatch學習筆記 (1)
  • watchConnectivity (1)
toggle 面試考題 (4)
  • 遞迴 (4)
  • C:選擇題 (2)
  • 常見面試考題 (8)
  • C:traceCode (2)
toggle appOnSale (1)
  • iOS (8)
toggle Java (1)
  • 檔案處理 (1)
toggle 英語學習 (2)
  • English idiom - 日常英文片語, 成語 (100)
  • English idiom - 日常英文片語, 成語 2 (16)
toggle Objective-C (2)
  • 類別, 物件與方法 (2)
  • 繼承 (2)
toggle 程式設計競賽題目 (3)
  • chapter1 (5)
  • chapter3 (1)
  • chapter2 (5)
toggle Linux (4)
  • Linux基本指令 (5)
  • Linux壓縮指令 (2)
  • Linux網路指令 (3)
  • Linux檔案與目錄管理 (1)
toggle 資料結構&演算法 (1)
  • sort排序 (2)
toggle android學習筆記 (7)
  • 其他 (1)
  • 網路服務相關 (1)
  • 用Intent啟動程式中其他activity (1)
  • SQLite資料庫 (2)
  • 事件處理 (5)
  • 多媒體相關 (1)
  • 控制元件相關 (11)
toggle iOS學習筆記 (7)
  • 其他 (14)
  • 初階UI設計 - 操作型元件 (13)
  • 初階UI設計 - 顯示型元件 (5)
  • 初階手勢gesture運用 (3)
  • 初階UI設計 - 指示型元件 (5)
  • 初階iOS內建裝置-多媒體功能 (7)
  • 初階iOS網路服務應用- 資料接收與傳送 (4)
  • 未分類文章 (1)

最新文章

  • iOS - NShopper (任天堂Switch商城特價遊戲查詢)
  • iOS - Bitcoin Miner (iOS比特幣挖礦程式)
  • iOS - Electronic Music Radio (免費電子音樂, 線上廣播)
  • iOS - Music Addict Radio (免費音樂, 完整曲風, 線上廣播)
  • iOS(Swift) - 播放影片
  • iOS(Swift) - 播放音樂
  • iOS(Swift) - 下載圖片並使用非同步傳輸
  • iOS - 2016/06/01之後app必須支援IPv6之問題
  • iOS - 後搖滾廣播電App(PostRock)
  • iOS - 調音器App(ThePitchPerfect)

最新留言

  • [24/08/23] 新飛Hsinfei 於文章「14. 英文片語 - had it co...」留言:
    實用日常英文合輯,5種生活英文對話情境,教你從常用英文開始學...
  • [23/01/06] 外約外送找小姐籟34386鐘點情人外約服務不只叫小姐素質好 臉蛋更優 想要找全套外約妹的朋友務必交給我 我將達成你最終性幻想對象Telegram:nini9595 於文章「iOS - Bitcoin Miner ...」留言:
    #奶糖外送茶 #外約 #舒壓 #喝茶籟34386和TG:ni...
  • [22/06/10] wecan如是外匯 於文章「3. 英文片語 - full plate...」留言:
    邀請你加入「外匯黃金虛擬貨幣技術信號Doo~Doo~」!請點...
  • [22/05/05] Unknown 於文章「65. 英文片語 - keep one'...」留言:
    Title: Keep one's word...
  • [22/04/24] 訪客 於文章「3-1. 陣列反轉輸出...」留言:
    原本在搜尋引擎找出一堆 Blog 文章,不知哪幾篇值得花時間...
  • [21/12/30] 康藥本鋪 kmed.tw 於文章「62. 英文片語 - on the sa...」留言:
    新聞BLOG https://kmed.tw/ind...
  • [21/03/28] 訪客 於文章「iOS - 控制camera閃光燈...」留言:
    「手機」,「虛擬網路」,[最高機密]。 --- ...
  • [21/03/28] 訪客 於文章「iOS - 控制camera閃光燈...」留言:
    一個錯誤的選擇 一個錯誤的環境 造就了 一連串 ...
  • [21/03/28] 訪客 於文章「iOS - 控制camera閃光燈...」留言:
    關閉系統基哨站。 這個世界,只不過是,謊言支撐起來,當...
  • [21/03/28] 訪客 於文章「iOS - 控制camera閃光燈...」留言:
    o•o 加油,別放棄,我們的星球,是變動的,生老病死,喜怒哀...

動態訂閱

文章精選

文章搜尋

誰來我家

參觀人氣

  • 本日人氣:
  • 累積人氣: