Я работаю над splitviewcontroller в оконном приложении. Я пишу код следующим образом, но выбор не работает
в LeftViewController.h:
#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