1

.xib这是我的问题:我用一些标签创建了一个。我创建了一个UITableViewController这样的:

- (void)viewDidLoad {
    [super viewDidLoad];
     dataToShow = [[NSArray alloc] initWithObjects:@"cave",@"garage",nil];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [dataToShow objectAtIndex:indexPath.row];

    return cell;
}

和正确填写numberOfSectionInTableViewnumberOfRowInSection当运行程序时,列表显示为它应该。我现在想根据用户在表格视图中单击的行来加载我创建的 xib 并用文本填充标签。这可能吗?如果是,我该如何解决?谢谢

4

2 回答 2

1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    yourNextViewController *nextViewXib = [[yourNextViewController alloc]initWithNibName:@"yourNextViewController" bundle:nil];
     nextViewXib.yourLable.text=[dataToShow objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:nextViewXib animated:YES];
    [nextViewXib release];
}
于 2012-11-06T10:46:36.907 回答
0
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

 NSLog(@"selected row:%d",indexPath.row);
}

 //in this mathod you get will row is calling..
于 2012-11-06T10:37:48.363 回答