我有一个TabBarController有4个选项卡,其中3个是表视图。我试图为每个表格视图单元格添加一个细节,并且我不认为故事板是有效的,因为我有超过50个详细页面。我对这一切都很陌生,我试图找出如何将细节链接到每个标签几个小时。我的表格视图从第二个视图控制器开始。 这里是SecondViewController.m:XCode TableViewController详细介绍Objective-C
#import "SecondViewController.h"
@implementation SecondViewController
{
NSArray *tableData;
}
@synthesize tableData;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
tableData = [NSArray arrayWithObjects:@"Carter", @"Greene", @"Hancock", @"Hawkins", @"Johnson", @"Sullivan", @"Unicoi", @"Washington", nil];
[super viewDidLoad];
}
#pragma mark - TableView Data Source methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
@end
这里是SecondViewController.h:
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController <UITableViewDelegate,
UITableViewDataSource>
@property(nonatomic, retain) NSArray *tableData;
@end
如果这会有所帮助,这里是我的故事板。
如果有人能帮助我单独以最无痛的方式详细信息添加到每个表视图单元格,我将不胜感激。谢谢!
您可能需要解释更多关于您的细节是什么意思?当用户点击一个单元格时打开一个详细视图控制器?请详细说明。 –
我使用Swift,所以不幸的是我可能无法在Obj-C中为您详细说明,但我可以提供高级解决方案。你应该创建另一个'UIViewController' .....说'DetailViewController'。您可以设置它的视觉方式,然后当用户点击一个“TableViewCell”时,对DetailViewController执行一个segue并将数据从单元传递到视图控制器。 –
你为什么认为故事板效率不高?根据我的经验,在故事板中可以有一些非常愚蠢的对象,并且它们在运行时被拆分并加载到零件中,很少有任何运行时问题。另外,你是否真的有50 *个不同的*详细页面,或者它们都是相同的布局,只是不同的内容? – zpasternack