0

UIViewControllerUITableViewがあります。セルに接続したい Storyboard で作成された他の UIViewControllers があります。

Storyboardで作成したUIViewControllerをセルに接続するにはどうすればよいですか?


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;
}
4

1 に答える 1

1

このコントローラーから他のコントローラーへのセグエを作成し、誰かがセルをタップしたときに実行するセグエを選択するか、ストーリーボードへの参照を使用して、instantiateViewControllerWithIdentifier:そのコントローラーを呼び出してタップ時にアクティブにすることができます。

于 2012-10-12T14:28:02.763 に答える