首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableView in UIViewController -连接单元到UIViewController

UITableView in UIViewController -连接单元到UIViewController
EN

Stack Overflow用户
提问于 2012-10-12 14:11:26
回答 1查看 573关注 0票数 0

我有一个UITableView在一个UIViewController。我在Storyboard中创建了其他UIViewControllers,我想连接到我的单元格。

如何将在Storyboard中创建的UIViewControllers连接到我的单元格?

MyViewController.h

代码语言:javascript
复制
@interface MyViewController : UIViewController <UITableViewDelegate,    UITableViewDataSource> {
    IBOutlet UITableView *myTableView;
}

@property (nonatomic, retain) UITableView *myTableView;

MyViewController.m

代码语言:javascript
复制
- (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;
}
EN

回答 1

Stack Overflow用户

发布于 2012-10-12 14:28:02

您可以从此控制器创建子到其他控制器,然后选择在某人点击单元格时执行哪个segue,或者可以使用对情节提要的引用来调用instantiateViewControllerWithIdentifier:,并在点击时激活该控制器。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12860916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档