使用splitViewControllers之间发送的数据更改uilabel文本

时间:2012-09-12 08:06:22

标签: ios5 uitabbarcontroller uisplitviewcontroller ipad

我在tabbar中学习splitViewController。我有5个选项卡,其中第5个是splitViewController。我能够证明这一点。我的MasterView确实将数据发送到DetailsView。但是DetailView标签不显示它

AppDelegate.m

- (void)showMainMenu:(NSNotification *)notification {

UserListViewController *userlist = [[UserListViewController alloc] init];  //MASTER VIEW

UINavigationController *userListNavController = [[UINavigationController alloc] initWithRootViewController:userlist];

UserDetailsViewController *userDetails = [[UserDetailsViewController alloc] init];  //DETAIL VIEW

UINavigationController *userDetailsNavController = [[UINavigationController alloc] initWithRootViewController:userDetails];

UISplitViewController *splitViewContr = [[UISplitViewController alloc] init];
splitViewContr.viewControllers = [NSArray arrayWithObjects:userListNavController,userDetailsNavController, nil];
splitViewContr.tabBarItem.image=kImage;
splitViewContr.title=@"Update User";

NSMutableArray *viewControllerArray = [[NSMutableArray alloc] init];
[viewControllerArray addObject:tab1];
[viewControllerArray addObject:tab2];
[viewControllerArray addObject:tab3];
[viewControllerArray addObject:tab4];
[viewControllerArray addObject:splitViewContr];

self._tabBarController.viewControllers=viewControllerArray;
[viewControllerArray release];

[self._tabBarController dismissModalViewControllerAnimated:NO];
}

UserListViewController.m

我有一个tableView。我只是展示didSelectRowAtIndexPath方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger item = [indexPath row];
NSNumber *detailItem = [NSNumber numberWithInteger:item];
userDetails = [[UserDetailsViewController alloc] init];
[self.userDetails setDetailItem:detailItem];
//self.userDetails.detailItem=detailItem;
}

UserDetailsViewController.m

- (void)setDetailItem:(NSNumber *)newDetailItem
{
if (detailItem != newDetailItem) {
    [detailItem release];
     detailItem= [newDetailItem retain];
    NSLog(@"DETAILS%@",detailItem);
    [self configureView];
}
}
- (void)configureView
{
if (self.detailItem) {
    [self viewDidLoad];
    //incomLabel.text=[NSString stringWithFormat:@"I got Demo %d",[detailItem integerValue]];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor whiteColor];
self.title=@"Update User Details";

incomLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, 250, 20)];

incomLabel.text=[NSString stringWithFormat:@"I got Demo %d",[detailItem integerValue]];
[self.view addSubview:incomLabel];
[incomLabel release];

}

如何使用来自Master类的数据更改Details Class中的标签文本。感谢

1 个答案:

答案 0 :(得分:0)

好的,我找到了答案。 我在AppDelegate.m userlist.userDetails=userDetails;中遗漏了这个东西,其中userDetails是UserListViewController里面的UserDetailsViewController对象。