splitViewCotroller中root/tableView的didSelectRowAtIndexpath方法 [英] didSelectRowAtIndexpath method for root / tableView in splitviewCotroller

查看:56
本文介绍了splitViewCotroller中root/tableView的didSelectRowAtIndexpath方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我在项目中使用了拆分视图控制器,
  • 在拆分视图中,我有RootViewCotroller(左), DetaolsViewConroller(右).
  • 在根"视图控制器中,我有3行.
  • 现在,我希望在细节视图中出现不同类型的外观 在rootview中选择不同的行.
  • ...
  • 在详细信息"视图中:
  • 1.选择第1行时显示tableView.
  • 2.选择第2行时显示一个文本字段.
  • 3.从rootviewcontroller中选择row3时的图像视图.
  • ..
  • 我在RootViecontroller中编写了这样的代码,但是在 detailsView.
  • --
  • I am using split view controller in my project,
  • in the split view i have RootViewCotroller (left), DetaolsViewConroller (right).
  • In the Root view controller, I have 3 rows.
  • Now I want different type of appearance in details view, when selecting different rows in rootview.
  • ...
  • in Details view:
  • 1.Display a tableView when select the row1.
  • 2.Dispaly a text field when select the row2.
  • 3.Image view when select row3 from rootviewcontroller.
  • ..
  • I wrote the code like this in RootViecontroller, but no change in detailsView.
  • -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

       {
           RightViewController *rightViewController = [[RightViewController alloc] initWithNibName:@"RightViewController"bundle:nil];
           //[self.navigationController pushViewController:rightViewController animated:YES];

           if(indexPath.row == 0)
           {
               UILabel *infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 450, 150)];
               infoLabel.text = @"Customer:Barrick \r\n Mine:gold \r\n Location:USA";
               [rightViewController.view addSubview:infoLabel];

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

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


           if(indexPath.row == 2)
           {
             image view..   
           }

           [rightViewController release];
       }

  • 该怎么办..?预先感谢.
  • 推荐答案

    您必须将值传递给右视图控制器,并且还必须为右视图控制器设置委托.

    You have to pass a value to the right view controller and you have to also set delegate for your right view controller.

    在左视图控制器中定义右视图控制器,例如:

    Define your right View Controller in your left view controller like:

    RightViewController *detail;
      /// in implementation of left view contrloller
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
        NSUInteger item = [indexPath row] +1;
        NSNumber *detailItem = [NSNumber numberWithInteger:item];
        self.detailCar.detailItem = detailItem;
    }
    

    在rightViewController.h文件中定义:

    Define in your rightViewController.h file :

    @property (retain, nonatomic) NSNumber *detailItem;
    

    在RightViewController的实现文件中:

    In Your RightViewController's implementation file:

    - (void)setDetailItem:(NSNumber *)newDetailItem {
        NSLog(@"ConfigTItem");
        if (_detailItem != newDetailItem) {
            [_detailItem release]; 
            _detailItem = [newDetailItem retain]; 
            [self configureView];
        }
        else {
            [self configureView]; 
        }
    }
    
    - (void)configureView {        
        if (self.detailItem) {
            [self viewDidLoad];  // 
            //set your method's and variable whatever you want to do in your view did load or directly here
        }
    }
    

    这篇关于splitViewCotroller中root/tableView的didSelectRowAtIndexpath方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆