2011-12-27 64 views
1

我在splitviewcontroller在基于窗口的应用程序 我写代码的工作如下,但didselect不LeftViewController.h工作在拆分视图控制器didSelect方法不工作

#import <UIKit/UIKit.h> 
@class RightViewController; 
@interface LeftViewController : UITableViewController 
{ 
    RightViewController *details; 
} 
@property (retain, nonatomic) NSNumber *detailItem; 

@end 

InLeftviewController.m :didselectmethod:

- (void)tableView:(UITableView *)tableView didDeSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    RightViewController *rightViewController = [[RightViewController alloc] initWithNibName:@"RightViewController" bundle:nil]; 
    [self.navigationController pushViewController:rightViewController animated:YES]; 

    NSUInteger item = [indexPath row]; 
    rightViewController.detailItem = [NSNumber numberWithInteger:item]; 
    rightViewController.detailItem = detailItem; 
    NSLog(@"detailItem= %@ , %@", detailItem,rightViewController.detailItem); 

    int i = [detailItem intValue]; 
    if(detailItem == [NSNumber numberWithInt:0]) 
    { 
     //Adding label to the details view 
     UILabel *infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 450, 150)]; 
     infoLabel.text = @"Customer:Barrick Gold\r\nMine:Turquiose Ridge Mine \r\nLocation:Mesa, AZ"; 
     [rightViewController.view addSubview:infoLabel]; 

     //Adding table view to the details view 
     UITableView *mapTable = [[UITableView alloc]initWithFrame:CGRectMake(165, 5, 450,150) style:UITableViewStyleGrouped]; 
     [rightViewController.view addSubview:mapTable]; 
    } 

    if(item == 1) 
    { 
     UILabel *infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 450, 150)]; 
     infoLabel.text = @"Eqipement"; 
     [rightViewController.view addSubview:infoLabel]; 
    } 

    if(i == 2) 
    { 

    } 
} 
在RightViewController.h

@interface RightViewController : UIViewController 
{ 
} 
@property (retain, nonatomic) NSNumber *detailItem; 

在RightViewController.m:

#import "RightViewController.h" 
#import "LeftViewController.h" 

@implementation RightViewController 
@synthesize detailItem; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) 
    { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)configureView 
{ 
    if (self.detailItem) 
    { 
     [self viewDidLoad]; 
    } 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    //set a background color Just to recognize the layout of the View 
    self.view.backgroundColor = [UIColor redColor]; 

    // To display Tiltle & EditButton on the navigation bar for this view controller. 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 
    self.title= @"Customer Name"; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (void)setDetailItem:(NSNumber *)newDetailItem 
{ 
    //LeftViewController *left = [[LeftViewController alloc]initWithNibName:@"LeftViewController" bundle:nil]; 
    int i = [detailItem intValue]; 
    NSLog(@"Config item %d",i); 

    if(detailItem == [NSNumber numberWithInt:0]) 
    { 
     NSLog(@"Configure item at row 1 %@",detailItem); 

     //Adding label to the view 
     UILabel *infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 450, 150)]; 
     infoLabel.text = @"Customer:Barrick Gold\r\nMine:Turquiose Ridge Mine \r\nLocation:Mesa, AZ"; 
     [self.view addSubview:infoLabel]; 

     //Adding table view to the view. 
     UITableView *mapTable = [[UITableView alloc]initWithFrame:CGRectMake(165, 5, 450,150) style:UITableViewStyleGrouped]; 
     [self.view addSubview:mapTable]; 
    } 

    if(detailItem == [NSNumber numberWithInt:1]) 
    { 
     NSLog(@"Config item at row 2 %@",detailItem); 
    } 

    if(self.detailItem == [NSNumber numberWithInt:2]) 
    { 
     NSLog(@"Config item at row 3 %@",detailItem); 
    } 

    if (detailItem != newDetailItem) 
    { 
     [detailItem release]; 
     detailItem = [newDetailItem retain]; 
     [self configureView]; 
    } 

    else 
    { 
     [self configureView]; 
    } 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return YES; 
} 

@end 
+0

你为什么使用分割视图。而不是splitview你可以休息一下你的朋友用UItableview和另一个视图概念所建议的例子。 – 2011-12-29 10:12:43

回答

0

尝试添加该线在leftView控制器的tableview的didSelect方法结束[self.navigationController pushViewController:rightViewController animated:YES];

+0

我曾尝试pusViewController,PresentModel视图控制器..即使没有结果先生 – 2011-12-27 09:45:24

+1

检查他更新的答案 – Hiren 2011-12-27 09:55:44

1

我不知道你想什么这里。如果LeftViewControllerRightViewController是拆分视图的主视图和详细视图,那么为什么要尝试从主视图推送详细视图。分割视图的功能是在右侧(细节视图)的详细视图中的主视图(左视图)中显示所选项目的详细信息。那么,为什么你会在主视图中推动这种观点。您所要做的就是设置DetailViewController的详细信息。

相关问题