麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

從零開始學(xué)ios開發(fā)(十五):NavigationControllersandTableViews(中)

2019-11-14 20:20:04
字體:
供稿:網(wǎng)友

這篇內(nèi)容我們繼續(xù)上一篇的例子接著做下去,為其再添加3個(gè)table view的例子,有了之前的基礎(chǔ),學(xué)習(xí)下面的例子會(huì)變得很簡單,很多東西都是舉一反三,稍稍有些不同的內(nèi)容,好了,閑話少說,開始這次的學(xué)習(xí)。

如果沒有上一篇的代碼,可以從這里下載Nav_1

1)第三個(gè)subtableview:Controls on Table Rows
這個(gè)例子,我們將為每個(gè)table view的每一行添加一個(gè)按鈕,這個(gè)按鈕將放在accessory icon的位置(之前我們使用過accessoryType,其實(shí)這也是一個(gè)view,可以容納其他的view,因此我們將一個(gè)button放在其中,然后accessory icon的位置上就會(huì)顯示button了,看了后面的例子就會(huì)明白)

同樣,選中PRoject navigator中的Nav文件夾,單擊鼠標(biāo)右鍵,選擇“New File...”,在彈出的窗口中,左邊選擇Cocoa Touch,右邊選擇Objective-C class,點(diǎn)擊Next按鈕,在下一個(gè)窗口中將class命名為BIDRowControlsController,Subclass of命名為BIDSecondLevelViewController,點(diǎn)擊Next按鈕,完成創(chuàng)建。

打開BIDRowControlsController.h,添加如下代碼

復(fù)制代碼
#import "BIDSecondLevelViewController.h"@interface BIDRowControlsController : BIDSecondLevelViewController@property (strong, nonatomic) NSArray *list;- (IBAction)buttonTapped:(id)sender;@end
復(fù)制代碼

list用戶保存table view中每一行顯示的數(shù)據(jù),buttonTapped事件用于按鈕的觸發(fā),大家也可以猜到,會(huì)是一個(gè)警告框彈出。(嚴(yán)格的來說這里不指定IBAction也可以,因?yàn)槲覀儾]有創(chuàng)建nib,也不會(huì)拖一個(gè)button到nib上面然后與其關(guān)聯(lián),定義一個(gè)普通的沒有返回值的方法即可,但是書里面還是推薦使用IBAction關(guān)鍵詞,這樣可以方面代碼的閱讀,可以知道這個(gè)方法是用于被某個(gè)控件觸發(fā)的。樓主木有試過這個(gè)方法,大家可以試試看,哈哈)

打開BIDRowControlsController.m,添加如下代碼

復(fù)制代碼
#import "BIDRowControlsController.h"@implementation BIDRowControlsController@synthesize list;- (IBAction)buttonTapped:(id)sender{    UIButton *senderButton = (UIButton *)sender;    UITableViewCell *buttonCell = (UITableViewCell *)[senderButton superview];    NSUInteger buttonRow = [[self.tableView indexPathForCell:buttonCell] row];    NSString *buttonTitle = [list objectAtIndex:buttonRow];    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You tapped the button"                                                    message:[NSString stringWithFormat:@"You tapped the button for %@", buttonTitle]                                                   delegate:nil                                          cancelButtonTitle:@"OK"                                          otherButtonTitles:nil];    [alert show];}- (void)viewDidLoad {    [super viewDidLoad];    NSArray *array = [[NSArray alloc] initWithObjects:@"R2-D2",                      @"C3PO", @"Tik-Tok", @"Robby", @"Rosie", @"Uniblab",                      @"Bender", @"Marvin", @"Lt. Commander Data",                      @"Evil Brother Lore", @"Optimus Prime", @"Tobor", @"HAL",                      @"Orgasmatron", nil];    self.list = array;}- (void)viewDidUnload{    [super viewDidUnload];    self.list = nil;}
復(fù)制代碼

這里添加了很常見的viewDidLoad和viewDidUnload,并且實(shí)現(xiàn)了buttonTapped方法,稍微解釋一下buttonTapped方法:
UIButton *senderButton = (UIButton *)sender; // 根據(jù)sender參數(shù)來確定是哪個(gè)button觸發(fā)了該事件,然后根據(jù)button所在的
UITableViewCell *buttonCell = (UITableViewCell *)[senderButton superview]; // 獲得button的superview,因?yàn)樵揵utton是在某一個(gè)的table cell上,因此它的superview就是UITableViewCell,因此這里可以強(qiáng)制的將button的superview轉(zhuǎn)換成UITableViewCell對象
NSUInteger buttonRow = [[self.tableView indexPathForCell:buttonCell] row]; // 根據(jù)獲得的table cell得到indexPath,再根據(jù)indexPath獲得button具體在第幾行
NSString *buttonTitle = [list objectAtIndex:buttonRow]; // 有第幾行,就可以在list中找到對應(yīng)的字符串了

接著添加table data source方法,添加如下代碼

復(fù)制代碼
#pragma mark -#pragma mark Table Data Source Methods- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return [list count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *ControlRowIdentifier = @"ControlRowIdentifier";        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ControlRowIdentifier];    if(cell == nil) {        cell = [[UITableViewCell alloc]                initWithStyle:UITableViewCellStyleDefault                reuseIdentifier:ControlRowIdentifier];        UIImage *buttonUpImage = [UIImage imageNamed:@"button_up.png"];        UIImage *buttonDownImage = [UIImage imageNamed:@"button_down.png"];        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];        button.frame = CGRectMake(0.0, 0.0, buttonUpImage.size.width, buttonUpImage.size.height);        [button setBackgroundImage:buttonUpImage forState:UIControlStateNormal];        [button setBackgroundImage:buttonDownImage forState:UIControlStateHighlighted];        [button setTitle:@"Tap" forState:UIControlStateNormal];        [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];        cell.accessoryView = button;    }    NSUInteger row = [indexPath row];    NSString *rowTitle = [list objectAtIndex:row];    cell.textLabel.text = rowTitle;        return cell;}
復(fù)制代碼

這2個(gè)方法也見了很多次了,對tableview:cellForRowAtIndexPath中的一些內(nèi)容進(jìn)行解釋:
UIImage *buttonUpImage = [UIImage imageNamed:@"button_up.png"]; // 載入button彈起狀態(tài)時(shí)的圖片
UIImage *buttonDownImage = [UIImage imageNamed:@"button_down.png"]; // 載入button按下時(shí)的圖片
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; // 創(chuàng)建一個(gè)button,這里沒有使用一般的創(chuàng)建方法[UIButton alloc],原因是如果使用了這樣的方法創(chuàng)建button,之中對這個(gè)button的外觀、文字等就不能進(jìn)行修改了,因此我們使用buttonWithType,并選擇UIButtonTypeCustom,自定義button外觀
button.frame = CGRectMake(0.0, 0.0, buttonUpImage.size.width, buttonUpImage.size.height); // 定義button的大小
[button setBackgroundImage:buttonUpImage forState:UIControlStateNormal]; // 用一張圖片設(shè)置button彈起時(shí)的狀態(tài)
[button setBackgroundImage:buttonDownImage forState:UIControlStateHighlighted]; // 用另一張圖片設(shè)置button按下時(shí)的狀態(tài)
[button setTitle:@"Tap"forState:UIControlStateNormal]; // 設(shè)置button的文字
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; // 為button添加事件,分2部分,首先是觸發(fā)哪個(gè)事件,另一個(gè)是在什么情況下觸發(fā),這里設(shè)置的觸發(fā)的事件是buttonTapped(IBAction類型,這是為什么剛才說不適用IBAction關(guān)鍵詞也可以,因?yàn)槲覀兪褂么a的方式為button制定了觸發(fā)的方法,因此不用IBAction),當(dāng)手指在button內(nèi)部彈起時(shí)才會(huì)觸發(fā)buttonTapped事件。
cell.accessoryView = button; // 在table cell的accessoryView的位置放置button

添加table的delegate方法,代碼如下

復(fù)制代碼
#pragma mark -#pragma mark Table Delegate Methods- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    NSUInteger row = [indexPath row];    NSString *rowTitle = [list objectAtIndex:row];    UIAlertView *alert = [[UIAlertView alloc]                          initWithTitle:@"You tapped the row."                          message:[NSString stringWithFormat:@"You tapped %@.", rowTitle]                          delegate:nil                          cancelButtonTitle:@"OK"                          otherButtonTitles:nil];    [alert show];    [tableView deselectRowAtIndexPath:indexPath animated:YES];}
復(fù)制代碼

這個(gè)方法的實(shí)現(xiàn)之前也見過,就對最后一句話解釋一下:
[tableView deselectRowAtIndexPath:indexPath animated:YES]; // 當(dāng)點(diǎn)擊table view中的一行時(shí),該行的背景色會(huì)變藍(lán),這句話的作用就是使其恢復(fù)成原來未選擇時(shí)的狀態(tài)

最后打開BIDFirstLevelController.m,添加如下代碼

復(fù)制代碼
#import "BIDFirstLevelController.h"#import "BIDSecondLevelViewController.h"#import "BIDDisclosureButtonController.h"#import "BIDCheckListController.h"#import "BIDRowControlsController.h"@implementation BIDFirstLevelController@synthesize controllers;- (void)viewDidLoad {    [super viewDidLoad];    self.title = @"First Level";    NSMutableArray *array = [[NSMutableArray alloc] init];        // Disclosure Button    BIDDisclosureButtonController *disclosureButtonController = [[BIDDisclosureButtonController alloc] initWithStyle:UITableViewStylePlain];    disclosureButtonController.title = @"Disclosure Buttons";    disclosureButtonController.rowImage = [UIImage imageNamed:@"disclosureButtonControllerIcon.png"];    [array addObject:disclosureButtonController];        // Checklist    BIDCheckListController *checkListController = [[BIDCheckListController alloc] initWithStyle:UITableViewStylePlain];    checkListController.title = @"Check One";    checkListController.rowImage = [UIImage imageNamed:@"checkmarkControllerIcon.png"];    [array addObject:checkListController];        // Row Controls    BIDRowControlsController *rowControlsController = [[BIDRowControlsController alloc] initWithStyle:UITableViewStylePlain];    rowControlsController.title = @"Row Controls";    rowControlsController.rowImage = [UIImage imageNamed:@"rowControlsIcon.png"];    [array addObject:rowControlsController];        self.controllers = array;}
復(fù)制代碼

這里就不解釋了,和之前的一樣。

編譯運(yùn)行,效果如下

多了最下面的Row Controls,我們點(diǎn)擊改行


每一個(gè)cell都有一個(gè)我們剛才定義的button在上面

我們點(diǎn)擊button,顯示效果如下

我們點(diǎn)擊行,顯示效果如下

這個(gè)例子就如此簡單的完成了,我們接著下一個(gè)例子。

2)第四個(gè)subtableview:Movable Rows 
這個(gè)例子是用來說明如何移動(dòng)table view中的每一行,可以對其重新進(jìn)行排序,在table view中有一個(gè)現(xiàn)成的方法叫做setEditing:animated,用于設(shè)置table view的內(nèi)容是否可以進(jìn)行編輯(edit)、刪除(delete)、插入(insert),如果我們要對table view中的內(nèi)容進(jìn)行操作,我們必須設(shè)置其為true,否則table view是不能進(jìn)行編輯的。這個(gè)例子中,我們將對table view中的行進(jìn)行操作,因此一定要設(shè)置其為true。廢話不多說,看來下面的例子就會(huì)更加清楚,好,現(xiàn)在開始這個(gè)例子。

選中Project navigator中的Nav文件夾,單擊鼠標(biāo)右鍵,選擇“New File...”,在彈出的窗口中,左邊選擇Cocoa Touch,右邊選擇Objective-C class,點(diǎn)擊Next按鈕,在下一個(gè)窗口中將class命名為BIDMoveMeController,Subclass of命名為BIDSecondLevelViewController,點(diǎn)擊Next按鈕,完成創(chuàng)建。

打開BIDMoveMeController.h,添加如下代碼

@interface BIDMoveMeController : BIDSecondLevelViewController@property (strong, nonatomic) NSMutableArray *list;- (IBAction)toggleMove;@end

list用于保存數(shù)據(jù),這里聲明的類型是NSMutableArray,因?yàn)槲覀円獙able view中的行進(jìn)行移動(dòng),因此list的內(nèi)容會(huì)發(fā)生變化,因此需要一個(gè)可變的Array。toggleMove方法用于打開/關(guān)閉table view的編輯模式。

打開BIDMoveMeController.m,添加如下代碼

復(fù)制代碼
#import "BIDMoveMeController.h"@implementation BIDMoveMeController@synthesize list;- (IBAction)toggleMove{    [self.tableView setEditing:!self.tableView.editing animated:YES];        if(self.tableView.editing)        [self.navigationItem.rightBarButtonItem setTitle:@"Done"];    else        [self.navigationItem.rightBarButtonItem setTitle:@"Move"];}- (void)viewDidLoad {    [super viewDidLoad];    if (list == nil) {        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:                                 @"Eeny", @"Meeny", @"Miney", @"Moe", @"Catch", @"A",                                 @"Tiger", @"By", @"The", @"Toe", nil];        self.list = array;    }        UIBarButtonItem *moveButton = [[UIBarButtonItem alloc]                                   initWithTitle:@"Move"                                   style:UIBarButtonItemStyleBordered                                   target:self                                   action:@selector(toggleMove)];    self.navigationItem.rightBarButtonItem = moveButton;}
復(fù)制代碼

先說一下toggleMove,這個(gè)方法是給navigator bar上右邊的按鈕調(diào)用的,
[self.tableView setEditing:!self.tableView.editing animated:YES]; // 通過self.tableView.editing屬性安排當(dāng)前table view的狀態(tài)是不是處于編輯模式,如果是,則變回非編輯模式,如果不是,則進(jìn)入編輯模式
if(self.tableView.editing// 如果是編輯模式
    [self.navigationItem.rightBarButtonItem setTitle:@"Done"]; // 設(shè)置navigator上右邊的按鈕文字為“Done”
else // 如果不是編輯模式
    [self.navigationItem.rightBarButtonItem setTitle:@"Move"]; // 設(shè)置navigator上右邊的按鈕文字為“Move”

在viewDidLoad方法中,我們創(chuàng)建了一個(gè)button(moveButton),然后將該button賦給navigator上右邊的按鈕。

大家有沒有注意到這里我們沒有定義viewDidUnload?我們在viewDidLoad中,也沒有每次都對list進(jìn)行創(chuàng)建,而是判斷l(xiāng)ist是否為nil,如果是,則生成list。我們?yōu)槭裁匆@么做呢?一個(gè)很重要的原因是之后我們將對list中的內(nèi)容進(jìn)行排序,如果每次都生成新的list,那么我們剛剛排好序的list就會(huì)丟失,這個(gè)是我們不希望發(fā)生的,因此我們在這里就不對list反復(fù)的進(jìn)行創(chuàng)建了。

好,接著添加如下代碼

復(fù)制代碼
#pragma mark -#pragma mark Table Data Source Methods- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return [list count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *MoveMeCellIdentifier = @"MoveMeCellIdentifier";    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MoveMeCellIdentifier];    if(cell == nil)    {        cell = [[UITableViewCell alloc]                initWithStyle:UITableViewCellStyleDefault                reuseIdentifier:MoveMeCellIdentifier];        cell.showsReorderControl = YES;    }    NSUInteger row = [indexPath row];    cell.textLabel.text = [list objectAtIndex:row];        return cell;}
復(fù)制代碼

在tableView:cellForRowAtIndexPath中,有一句新的代碼:
cell.showsReorderControl = YES; // 它的作用是顯示reorder的控件(重新排序的控件),比較奇怪的是我試過把這句話注釋掉,但是哪個(gè)排序控件依然出現(xiàn),不知道為什么。

接著添加代碼

復(fù)制代碼
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{    return UITableViewCellEditingStyleNone;}- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{    return YES;}- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{    NSUInteger fromRow = [fromIndexPath row];    NSUInteger toRow = [toIndexPath row];        id object = [list objectAtIndex:fromRow];    [list removeObjectAtIndex:fromRow];    [list insertObject:object atIndex:toRow];}
復(fù)制代碼

上面3個(gè)方法都是第一次看見,第一個(gè)方法tableView:editingStyleForRowAtIndexPath用于制定tableview是否可以進(jìn)行刪除或者插入操作,在這里我們僅僅是進(jìn)行排序,所以返回的對象是UITableViewCellEditingStyleNone。第二個(gè)方法tableView:canMoveRowAtIndexPath,指定是否可以移動(dòng)行。最后一個(gè)方法tableView:moveRowAtIndexPath是移動(dòng)行后進(jìn)行操作的方法,記錄一行的起始位置和終點(diǎn),然后在list中把先備份一下起始位置的值,然后刪除,最后再終點(diǎn)位置插入備份值,ok,完成移動(dòng)操作。怎么樣,還是很直接和簡單的吧。

打開BIDFirstLevelController.m,添加最后的代碼

復(fù)制代碼
#import "BIDFirstLevelController.h"#import "BIDSecondLevelViewController.h"#import "BIDDisclosureButtonController.h"#import "BIDCheckListController.h"#import "BIDRowControlsController.h"#import "BIDMoveMeController.h"@implementation BIDFirstLevelController@synthesize controllers;- (void)viewDidLoad {    [super viewDidLoad];    self.title = @"First Level";    NSMutableArray *array = [[NSMutableArray alloc] init];        // Disclosure Button    BIDDisclosureButtonController *disclosureButtonController = [[BIDDisclosureButtonController alloc] initWithStyle:UITableViewStylePlain];    disclosureButtonController.title = @"Disclosure Buttons";    disclosureButtonController.rowImage = [UIImage imageNamed:@"disclosureButtonControllerIcon.png"];    [array addObject:disclosureButtonController];        // Checklist    BIDCheckListController *checkListController = [[BIDCheckListController alloc] initWithStyle:UITableViewStylePlain];    checkListController.title = @"Check One";    checkListController.rowImage = [UIImage imageNamed:@"checkmarkControllerIcon.png"];    [array addObject:checkListController];        // Row Controls    BIDRowControlsController *rowControlsController = [[BIDRowControlsController alloc] initWithStyle:UITableViewStylePlain];    rowControlsController.title = @"Row Controls";    rowControlsController.rowImage = [UIImage imageNamed:@"rowControlsIcon.png"];    [array addObject:rowControlsController];        // Move Me    BIDMoveMeController *moveMeController = [[BIDMoveMeController alloc] initWithStyle:UITableViewStylePlain];    moveMeController.title = @"Move Me";    moveMeController.rowImage = [UIImage imageNamed:@"moveMeIcon.png"];    [array addObject:moveMeController];        self.controllers = array;}
復(fù)制代碼

編譯運(yùn)行

進(jìn)入Move Me后

點(diǎn)擊navigator上右邊的Move按鈕

按鈕的文字變成了“Done”,然后tableview中每一行的右邊都出現(xiàn)了一個(gè)reorder的圖標(biāo),將手指放在上面逗留一會(huì),你點(diǎn)中的那一行會(huì)“浮起”,接著你就可以隨意移動(dòng)了,移到你想要的地方后放手即可。

3)第五個(gè)subtableview:Deletable Rows 
這個(gè)例子展示的是如何刪除table view中的行,這次我們不再在viewDidLoad中對table view的內(nèi)容進(jìn)行定義,而是從外部的一個(gè)文件進(jìn)行導(dǎo)入,首先下載這里的computers.plist.zip,解壓縮后拖入到Project navigator下的Nav文件夾下

好,下面可以開始添加新的文件了,選中Project navigator中的Nav文件夾,單擊鼠標(biāo)右鍵,選擇“New File...”,在彈出的窗口中,左邊選擇Cocoa Touch,右邊選擇Objective-C class,點(diǎn)擊Next按鈕,在下一個(gè)窗口中將class命名為BIDDeleteMeController,Subclass of命名為BIDSecondLevelViewController,點(diǎn)擊Next按鈕,完成創(chuàng)建。

打開BIDDeleteMeController.h文件,添加如下代碼

復(fù)制代碼
#import "BIDSecondLevelViewController.h"@interface BIDDeleteMeController : BIDSecondLevelViewController@property (strong, nonatomic) NSMutableArray *list;- (IBAction)toggleEdit:(id)sender;@end
復(fù)制代碼

應(yīng)該可以想到,我們肯定要聲明一個(gè)NSMutableArray,因?yàn)樾枰獎(jiǎng)h除其中的項(xiàng),toggleEdit方法用于table view狀態(tài)的切換。

打開BIDDeleteMeController.m文件,添加如下代碼

復(fù)制代碼
#import "BIDDeleteMeController.h"@implementation BIDDeleteMeController@synthesize list;- (IBAction)toggleEdit:(id)sender{    [self.tableView setEditing:!self.tableView.editing animated:YES];        if(self.tableView.editing)        [self.navigationItem.rightBarButtonItem setTitle:@"Done"];    else        [self.navigationItem.rightBarButtonItem setTitle:@"Delete"];}- (void)viewDidLoad{    [super viewDidLoad];    if(list == nil)    {        NSString *path = [[NSBundle mainBundle] pathForResource:@"computers" ofType:@"plist"];        NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];        self.list = array;    }    UIBarButtonItem *editButton = [[UIBarButtonItem alloc]                                   initWithTitle:@"Delete"                                   style:UIBarButtonItemStyleDone                                   target:self                                   action:@selector(toggleEdit:)];    self.navigationItem.rightBarButtonItem = editButton;}
復(fù)制代碼

應(yīng)該不會(huì)覺得有看不懂的地方吧,和之前的一個(gè)例子是一樣的,那么就接著添加代碼吧

復(fù)制代碼
#pragma mark -#pragma mark Table Data Source Methods- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return [list count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *DeleteMeCellIdentifier = @"DeleteMeCellIdentifier";        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DeleteMeCellIdentifier];        if(cell == nil)    {        cell = [[UITableViewCell alloc]                initWithStyle:UITableViewCellStyleDefault                reuseIdentifier:DeleteMeCellIdentifier];    }        NSInteger row = [indexPath row];    cell.textLabel.text = [list objectAtIndex:row];    return cell;}
復(fù)制代碼

額~~~貌似也不用解釋,好吧,就不解釋了,繼續(xù)添加代碼

復(fù)制代碼
#pragma mark -#pragma mark Table View Data Source Methods- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{    NSUInteger row = [indexPath row];    [self.list removeObjectAtIndex:row];    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]                     withRowAnimation:UITableViewRowAnimationAutomatic];}
復(fù)制代碼

這是一個(gè)新的方法,第一次使用,當(dāng)用戶要?jiǎng)h除table view中的一行或者進(jìn)行插入操作時(shí),會(huì)觸發(fā)該方法。其中第二個(gè)參數(shù)有三個(gè)值,分別是:
UITableViewCellEditingStyleNone:什么操作都不執(zhí)行(這個(gè)值在上一個(gè)例子中使用過)
UITableViewCellEditingStyleDelete:刪除操作
UITableViewCellEditingStyleInsert:插入操作

這個(gè)方法里面的具體代碼還是很好理解的,都不多做解釋了。

打開BIDFirstLevelController.m,添加最后的代碼

復(fù)制代碼
#import "BIDFirstLevelController.h"#import "BIDSecondLevelViewController.h"#import "BIDDisclosureButtonController.h"#import "BIDCheckListController.h"#import "BIDRowControlsController.h"#import "BIDMoveMeController.h"#import "BIDDeleteMeController.h"@implementation BIDFirstLevelController@synthesize controllers;- (void)viewDidLoad {    [super viewDidLoad];    self.title = @"First Level";    NSMutableArray *array = [[NSMutableArray alloc] init];        // Disclosure Button    BIDDisclosureButtonController *disclosureButtonController = [[BIDDisclosureButtonController alloc] initWithStyle:UITableViewStylePlain];    disclosureButtonController.title = @"Disclosure Buttons";    disclosureButtonController.rowImage = [UIImage imageNamed:@"disclosureButtonControllerIcon.png"];    [array addObject:disclosureButtonController];        // Checklist    BIDCheckListController *checkListController = [[BIDCheckListController alloc] initWithStyle:UITableViewStylePlain];    checkListController.title = @"Check One";    checkListController.rowImage = [UIImage imageNamed:@"checkmarkControllerIcon.png"];    [array addObject:checkListController];        // Row Controls    BIDRowControlsController *rowControlsController = [[BIDRowControlsController alloc] initWithStyle:UITableViewStylePlain];    rowControlsController.title = @"Row Controls";    rowControlsController.rowImage = [UIImage imageNamed:@"rowControlsIcon.png"];    [array addObject:rowControlsController];        // Move Me    BIDMoveMeController *moveMeController = [[BIDMoveMeController alloc] initWithStyle:UITableViewStylePlain];    moveMeController.title = @"Move Me";    moveMeController.rowImage = [UIImage imageNamed:@"moveMeIcon.png"];    [array addObject:moveMeController];        // Delete Me    BIDDeleteMeController *deleteMeController = [[BIDDeleteMeController alloc] initWithStyle:UITableViewStylePlain];    deleteMeController.title = @"Delete Me";    deleteMeController.rowImage = [UIImage imageNamed:@"deleteMeIcon.png"];    [array addObject:deleteMeController];        self.controllers = array;}
復(fù)制代碼

編譯運(yùn)行

選擇Delete Me進(jìn)入

點(diǎn)擊右上角的Delete按鈕

點(diǎn)擊左邊的紅圈,出現(xiàn)刪除按鈕

點(diǎn)擊Delete按鈕,刪除改行

再次點(diǎn)擊右上角的Done,還原

另外一種產(chǎn)用的刪除方法,直接在某一行上劃一下,出現(xiàn)Delete按鈕,刪除

4)總結(jié)
好了,這篇三個(gè)例子的講解就到此為止,對table view各個(gè)方面的屬性進(jìn)行說明,都是一些很常見的操作,以后在開發(fā)app的時(shí)候也一定會(huì)使用到這些常用的功能。希望各位能夠看懂,也再次感謝給我留言的每一位朋友,你們是我繼續(xù)寫下去的動(dòng)力!


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 91天堂国产在线 | 狠狠撸电影| 宅男噜噜噜66国产免费观看 | 国产v综合v亚洲欧美久久 | 久久精品九九 | 欧美一级理论 | 国产一级淫片免费看 | 久久96国产精品久久秘臀 | 福利在线免费 | 欧美中文字幕一区二区三区亚洲 | 久草干 | 亚洲卡通动漫在线观看 | 羞羞草视频| 亚洲一区二区在线视频 | 91精品最新国内在线播放 | 国产中文一区 | 毛片大全免费 | 欧美交在线 | 精品国产一区二区三区久久久蜜月 | 国产1区2区3区在线观看 | 国产色视频一区 | 久久久久久中文字幕 | 免费的性生活视频 | 一区二区三区欧美日韩 | 国产精品99久久久久久董美香 | 免费人成在线观看网站 | 欧美成年人在线视频 | a级毛片免费观看在线播放 日本aaa一级片 | 黄色电影免费提供 | 天天夜夜操操 | 91精品国产九九九久久久亚洲 | 91网页视频入口在线观看 | 一起草av在线 | 久久精品一二三区 | 99riav视频一区二区 | 91精品国产乱码久久桃 | 欧美一级免费在线观看 | 久草在线资源视频 | 国产精品久久久久久久久岛 | 成人午夜亚洲 | 国产手机在线视频 |