简体   繁体   English

普通视图控制器中的tableview

[英]tableview in normal view controller

I am doing the project which need to use the storyboard to rewrite the old project. 我正在做的项目需要使用情节提要重写旧项目。 I got some problems when I doing it use the storyboard. 使用情节提要板时遇到一些问题。 I use the normal view controller instead of tableview controller, because there are some buttons and labels in this view controller. 我使用普通的视图控制器而不是tableview控制器,因为此视图控制器中有一些按钮和标签。 The problem is I don't know how to link between this view controller and the detail view controller when users select the cell from the table view. 问题是当用户从表视图中选择单元格时,我不知道如何在此视图控制器和详细视图控制器之间进行链接。

Select a cell in the Table View. 在表格视图中选择一个单元格。 And make a segue to the DetailViewController by ctrl clicking on the Table Cell and dragging to the DetailViewController in the Storyboard. 并作出SEGUE到DetailViewController通过在表格单元格CTRL单击并拖动到DetailViewController在故事板。 Then select a segue type based on the type of transition you want: modal, or push (if these view controllers are embedded in a navigation controller, etc.) 然后根据所需的过渡类型选择模式类型:模态或推送(如果这些视图控制器嵌入在导航控制器中,等等)

可能您应该使用以下代码:

[self.navigationController pushViewController:[YourNewViewControllerClass new] animated:YES];

simply drag the tableview to a normal VC. 只需将tableview拖动到普通VC。

ctrl+drag from your table to the orange circle below to connect as delegate/datasource. 按住Ctrl键并从表格中拖动到下面的橙色圆圈,以作为委托/数据源进行连接。

make your VC to implement uitableview delegate and datasource protocols ( @interface MyVC : UIViewController <UITableViewDataSource, UITableViewDelegate> ). 使您的VC实现uitableview委托和数据源协议( @interface MyVC : UIViewController <UITableViewDataSource, UITableViewDelegate> )。

write the mandatory protocol methods: 编写强制协议方法:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM