我有一个UITableView在一个UIViewController。我在Storyboard中创建了其他UIViewControllers,我想连接到我的单元格。
如何将在Storyboard中创建的UIViewControllers连接到我的单元格?
MyViewController.h
@interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *myTableView;
}
@property (nonatomic, retain) UITableView *myTableView;MyViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *array = [[NSArray alloc] initWithObjects:@"CELL1", @"CELL2 & CELL3", nil];
self.listData = array;
[array release];
[myTableView setDataSource:self];
[myTableView setDelegate:self];
[[self view] addSubview:myTableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UpdatesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"UpdatesTableViewCell" owner:nil options:nil];
for (UIView *view in views) {
if([view isKindOfClass:[UITableViewCell class]])
{
cell = (UpdatesTableViewCell*)view;
}
}
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
}发布于 2012-10-12 14:28:02
您可以从此控制器创建子到其他控制器,然后选择在某人点击单元格时执行哪个segue,或者可以使用对情节提要的引用来调用instantiateViewControllerWithIdentifier:,并在点击时激活该控制器。
https://stackoverflow.com/questions/12860916
复制相似问题