问题描述
我在基于窗口的应用程序中使用splitviewcontroller
我正在编写如下代码,但是在LeftViewController.h中确实没有工作
i am working on splitviewcontroller in window based applicationim writing code as follows but didselect not working
:
#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)
{
}
}
:
@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
推荐答案
我不确定你在这里尝试的是什么。如果 LeftViewController
和 RightViewController
是拆分视图的主视图和详细视图,那么为什么要尝试推送细节从主视图查看。拆分视图的功能是在右侧的详细视图(详细视图)上显示主视图(左视图)中所选项目的详细信息。那你为什么要在主视图中推动该视图呢?您所要做的就是设置 DetailViewController
的详细信息。
I am not sure what you are trying here. If the LeftViewController
and RightViewController
are the master and detail views of the split view then why are you trying to push the detail view from the master view. The function of the split view is to show the details of the selected item in the master view(left view) on the detail view on the right side(detail view). So why would you bother pushing that view in the master view. All you have to do is to set the detail item for the DetailViewController
.
这篇关于在拆分视图控制器didSelect方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!