这是我的问题:
我创建了一个带有标签的.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;
}
numberOfSectionInTableView
和numberOfRowInSection
被正确填充,当运行程序时,列表显示应该如此。我想现在,根据用户在表格视图中单击哪一行,加载我创建的xib并用文本填充标签。这是可能的,如果是的话,我该怎么把它拉掉?感谢
答案 0 :(得分: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];
}
答案 1 :(得分:0)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"selected row:%d",indexPath.row);
}
//in this mathod you get will row is calling..