IOS5基礎十五-----展示詳情表和校驗表

暫時先貼代碼,其他的全部寫完在補充!

#import "BIDSecondLevelViewController.h"

@interface BIDDisclosureButtonController : BIDSecondLevelViewController

@property (strong,nonatomic) NSArray *list;

@end


#import "BIDDisclosureButtonController.h"

#import "BIDAppDelegate.h"

#import "BIDDisclosureDetailController.h"


//這種聲明的類別方式稱爲類擴展(class extension)

@interface BIDDisclosureButtonController()

@property (strong,nonatomic) BIDDisclosureDetailController *childController;

@end


@implementation BIDDisclosureButtonController

@synthesize list;

@synthesize childController;


-(void)viewDidLoad

{

    [super viewDidLoad];

    NSArray *array=[[NSArray alloc] initWithObjects:@"Toy Story",@"A Bus's Life",@"Toy Story 2",@"Monsters,Inc.",@"Finding Nemo",@"The Incredibles",@"Cars",@"Ratatouile",@"WALL-E",@"Up",@"Toy Story 3",@"Cars 2",@"Brave",nil];

    self.list=array;

}


-(void)viewDidUnload

{

    [super viewDidUnload];

    self.list=nil;

    self.childController=nil;

}


#pragma mark -

#pragma mark Table Data Source Methods

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

{

    return [self.list count];

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *DisclosureButtonCellIdentifier= @"DisclosureButtonCellIdentifier";

    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:DisclosureButtonCellIdentifier];

    if (cell==nil) {

        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DisclosureButtonCellIdentifier];

    }

    NSInteger row=[indexPath row];

    NSString *rowString=[list objectAtIndex:row];

    cell.textLabel.text=rowString;

    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;

    return cell;

}



#pragma  mark -

#pragma  mark Table Detegate Methods

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Hey,do you see the disclosure button?" message:@"If you're trying to drill down,touch that instead" delegate:nil cancelButtonTitle:@"Won't happen again" otherButtonTitles:nil];

    [alert show];

}


-(void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

{

    if (childController==nil) {

        childController=[[BIDDisclosureDetailController alloc] initWithNibName:@"BIDDisclosureDetail" bundle:nil];

    }

    

    childController.title=@"Disclosure Button Pressed";

    NSUInteger row=[indexPath row];

    NSString *selectedMovie=[list objectAtIndex:row];

    NSString *detailMessage=[[NSString alloc] initWithFormat:@"You Pressed the disclosure button for %@",selectedMovie];

    childController.message=detailMessage;

    childController.title=selectedMovie;

    [self.navigationController pushViewController:childController animated:YES];

}

@end



#import <UIKit/UIKit.h>


@interface BIDDisclosureDetailController : UIViewController

@property (strong,nonatomic) IBOutlet UILabel *label;

@property (copy,nonatomic) NSString *message;//這裏使用copy可能存在的可變的字符串

//這裏要注意一個延遲加載的概念,也就是說只有當我們調用改頁面時,纔會把這些數據顯示出來。

@end


#import "BIDDisclosureDetailController.h"


@implementation BIDDisclosureDetailController

@synthesize label;

@synthesize message;


-(void)viewWillAppear:(BOOL)animated//viewDidload只在第一次加載的時候被調用,如果使用viewDidload來處理,該視圖將只在BIDDisclosureDetailCintroller視圖第一次出現的時候得到更新,在第二次選取Pixar按鈕時。我們仍會看到來自第一個按鈕的詳細信息。

{

    label.text=message;

    [super viewWillAppear:animated];

}


-(void)viewDidUnload

{

    [super viewDidUnload];

    self.label=nil;

    self.message=nil;

}


@end




BIDCheckListController.h

#import "BIDSecondLevelViewController.h"


@interface BIDCheckListController : BIDSecondLevelViewController

@property (strong,nonatomic) NSArray *list;

@property (strong,nonatomic) NSIndexPath *lastIndexPath;

@end


BIDCheckListController.m

#import "BIDCheckListController.h"


@implementation BIDCheckListController

@synthesize list;

@synthesize lastIndexPath;


-(void) viewDidLoad

{

    [super viewDidLoad];

    NSArray *array=[[NSArray alloc] initWithObjects:@"Who Hash",@"Bubba Gump Shrimp Etouffee",@"Who Pudding",@"Scooby Snacks",@"Everlasting Gobstopper",@"Green Eggs and Hams",@"Sonlent Green",@"Hard Tack",@"Lembas Bread",@"Roast Beast",@"Blancmange", nil];

    self.list=array;

}


-(void) viewDidUnload

{

    [super viewDidUnload];

    self.list=nil;

    self.lastIndexPath=nil;

}


#pragma mark -

#pragma mark Table Data Source Methods

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

{

    return [self.list count];

}


-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CheckMarkCellIdentifier=@"CheckMarkCellIdentifier";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CheckMarkCellIdentifier];

    if (cell==nil) {

        cell=[[UITableViewCell  alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CheckMarkCellIdentifier];

    }

    NSInteger row=[indexPath row];

    NSInteger oldRow=[lastIndexPath row];

    cell.textLabel.text=[list objectAtIndex:row];

    cell.accessoryType=(row==oldRow && lastIndexPath!=nil)?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;

    return cell;

}


#pragma mark -

#pragma mark Table Delegate Methods

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    int newRow =[indexPath row];

    int oldRow=(lastIndexPath !=nil)?[lastIndexPath row]:-1 ;

    if (newRow!=oldRow) {

        UITableViewCell *newCell=[tableView cellForRowAtIndexPath:indexPath];

        newCell.accessoryType=UITableViewCellAccessoryCheckmark;

        UITableViewCell *oldCell=[tableView cellForRowAtIndexPath:lastIndexPath];

        oldCell.accessoryType=UITableViewCellAccessoryNone;

        lastIndexPath=indexPath;

    }

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}



@end




發佈了102 篇原創文章 · 獲贊 35 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章