在选择tableview项时更新ViewController文本框

时间:2012-12-25 18:23:45

标签: ios cocoa-touch uitableview

我创建了一个基于视图的应用程序,为没有导航控制器的Iphone故事板提供模态链接的视图控制器。对于我的一个View Controllers,我设计了一个包含动态单元格的tableview:

- (void)viewDidLoad {
[super viewDidLoad];

tabledata =[[NSArray alloc] initWithObjects:@"Data Mining",@"Software Quality",@"Project Management",@"Data Base", nil]; 
tablesubtitles =[[NSArray alloc] initWithObjects:@"Test parsing and KDD",@"Management of Software Creation Cycle",@"Roles in a Project",@"Database Lifecycle process", nil]; 


- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [tabledata count];
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell=nil;

cell= [ tableView dequeueReusableCellWithIdentifier:@"Cell1"];

if (cell == nil) {
    cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell1"];
}

cell.textLabel.text= [tabledata objectAtIndex:indexPath.row];
cell.detailTextLabel.text =[tablesubtitles objectAtIndex:indexPath.row];
return cell;
}

我想要实现的另一件事是将tableview行链接到一个ViewController,它有几个可用的文本框。最大的想法是,在选择一个TableItem时,我想加载一个ViewController并根据所选项自动填充文本框,最好还是有编辑/保存的可能性。

例如:我有一个带有项目的Tableview

道奇 克莱斯勒 Chevrolete 福特

在按下“Dodge”时,会出现一个新的ViewController,其中包含多个TextBox,并且数据填入了一些细节,例如“自1900年以来”。 在编辑“自1900年以来”文本框并按下“保存”按钮后,控件将返回到包含TableView的viewcontroller。

按“Dodge”后,第二次显示以前保存的项目。

我尝试了很多变种,组合如何实现它,我是Xcode的新手,任何帮助都会很受欢迎。

提前谢谢。

1 个答案:

答案 0 :(得分:1)

这并不难。基本上你只需要在你的UITableView委托中实现didSelectRowAtIndexPath。要了解如何执行此操作,请在XCode中创建一个新项目并使其成为MasterDetail应用程序。这为您提供了具有可选行的表视图的样板代码。主视图是您的表,详细信息视图是您处理所选行的方式。