IOS SDK在表视图设置窗格中

时间:2011-03-10 20:50:34

标签: iphone cocoa-touch ios uitableview

好吧基本上就是这样。我正在尝试编写一个基本的任务管理器,但此时您只需选择任务并将其传递到另一个窗格以获取详细信息。如何使内部的tableview看起来像本机设置应用程序?

> #import "RootViewController.h"
> #import "DetailViewController.h" @implementation RootViewController
> @synthesize toolbar; @synthesize
> window;
> 
> #pragma mark -
> #pragma mark View lifecycle
> 
> 
> 
> - (void)viewDidLoad {     theArray = [[NSArray alloc]
> initWithObjects:@"Kill Taylor",@"Stab
> Taylor",@"Pay Jordan",nil];
>   //theArray = [[NSMutableArray alloc]
> init];
>   
> 
>     [super viewDidLoad];
> 
>   addButton = [[UIBarButtonItem alloc]
> initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
> target:self
> action:@selector(addButtonPressed)];
>   self.navigationItem.rightBarButtonItem
> = addButton;  self.navigationItem.leftBarButtonItem
> = self.editButtonItem;    //self.navigationItem.rightBarButtonItem
> = addButton;    // self.navigationItem.rightBarButtonItem
> = addButton;
>     // Uncomment the following line to display an Edit button in the
> navigation bar for this view
> controller.
>     // self.navigationItem.rightBarButtonItem
> = self.editButtonItem; }
> 
> 
> -(void) addButtonPressed {    NSString *selectedAction = @"add";
>   
> 
>   DetailViewController *dvController =
> [[DetailViewController alloc]
> initWithNibName:@"DetailView"
> bundle:[NSBundle mainBundle]];
>   dvController.selectedAction =
> selectedAction;
>   //dvController.selectedTask =
> selectedTask;
>   [self.navigationController
> pushViewController:dvController
> animated:YES];    [dvController
> release];     dvController = nil; }
> 
> 
> - (void)viewWillAppear:(BOOL)animated {
>     [super viewWillAppear:animated];   }
> 
> /*
> - (void)viewDidAppear:(BOOL)animated {
>     [super viewDidAppear:animated]; }
> */ /*
> - (void)viewWillDisappear:(BOOL)animated
> {     [super viewWillDisappear:animated];
> }
> */ /*
> - (void)viewDidDisappear:(BOOL)animated
> {     [super viewDidDisappear:animated];
> }
> */
> 
> /*  // Override to allow orientations
> other than the default portrait
> orientation.
> - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
> {     // Return YES for supported
> orientations.     return
> (interfaceOrientation ==
> UIInterfaceOrientationPortrait); }  */
> 
> 
> 
> // Customize the number of sections in
> the table view.
> - (NSInteger)numberOfSectionsInTableView:(UITableView
> *)tableView {
>     return 1; }
> 
> 
> // Customize the number of rows in the
> table view.
> - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
> {     return [theArray count];
> 
> }
>  
> 
> 
> // Customize the appearance of table
> view cells.
> - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
> *)indexPath {
>     
>     static NSString *CellIdentifier = @"Cell";
>     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
>     if (cell == nil) {
>         cell = [[[UITableViewCell alloc]
> initWithStyle:UITableViewCellStyleDefault
> reuseIdentifier:CellIdentifier]
> autorelease];
>     }
>   
>     cell.textLabel.text = [theArray objectAtIndex:indexPath.row];    
>     return cell;   }
> - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
>     if (editing)
>     {
>         // turn on the "add" button when editing
>         //self.navigationItem.rightBarButtonItem
> = addButton;
>     }
>     else
>     {
>         // remove the "add" butto when not editing
>         //self.navigationItem.rightBarButtonItem
> = nil;
>     }
>   
>      [super setEditing:editing animated:animated]; }
> 
> 
> /* // Override to support conditional
> editing of the table view.
> - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath
> *)indexPath {
>     // Return NO if you do not want the specified item to be editable.
>     return YES; }
> */
> 
> 
> /* // Override to support editing the
> table view.
> - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
> forRowAtIndexPath:(NSIndexPath
> *)indexPath {
>     
>     if (editingStyle == UITableViewCellEditingStyleDelete) {
>         // Delete the row from the data source.
>         [tableView deleteRowsAtIndexPaths:[NSArray
> arrayWithObject: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.
>     }    }
> */
> 
> 
> /* // Override to support rearranging
> the table view.
> - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath
> *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
> { }
> */
> 
> 
> /* // Override to support conditional
> rearranging of the table view.
> - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath
> *)indexPath {
>     // Return NO if you do not want the item to be re-orderable.
>     return YES; }
> */
> 
> 
> #pragma mark -
> #pragma mark Table view delegate
> 
> - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
> *)indexPath {     NSString *selectedAction = @"details";  NSString *selectedTask = [theArray
> objectAtIndex:indexPath.row];
>   DetailViewController *dvController =
> [[DetailViewController alloc]
> initWithNibName:@"DetailView"
> bundle:[NSBundle mainBundle]];
>   dvController.selectedAction =
> selectedAction;
>   dvController.selectedTask =
> selectedTask;
>   [self.navigationController
> pushViewController:dvController
> animated:YES];    [dvController
> release];     dvController = nil;      }
> 
> 
> #pragma mark -
> #pragma mark Memory management
> 
> - (void)didReceiveMemoryWarning {
>     // Releases the view if it doesn't have a superview.
>     [super didReceiveMemoryWarning];
>     
>     // Relinquish ownership any cached data, images, etc that aren't in use.
> }
> 
> - (void)viewDidUnload {
>     // Relinquish ownership of anything that can be recreated in
> viewDidLoad or on demand.
>     // For example: self.myOutlet = nil; }
> 
> 
> - (void)dealloc {
>     [super dealloc]; }
> 
> 
> @end

先谢谢了, - 迈克尔

2 个答案:

答案 0 :(得分:2)

在界面构建器中选择tableview。然后去酒店。应该有类似风格的东西。切换它,你有你的梦想的桌面视图: - )

答案 1 :(得分:0)

在表视图属性检查器中,样式:分组