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




你可能感兴趣的:(list,table,button,interface,extension,ios5)