Iphone 是否为uitableview中的每条记录添加表单元格?
我正在尝试实现一个系统,在这个系统中,用户最初会在uinavigationview中以uitableview(分组样式)显示一个单独的tablecellIphone 是否为uitableview中的每条记录添加表单元格?,iphone,objective-c,uitableview,uinavigationcontroller,Iphone,Objective C,Uitableview,Uinavigationcontroller,我正在尝试实现一个系统,在这个系统中,用户最初会在uinavigationview中以uitableview(分组样式)显示一个单独的tablecell --------------- + | add record | --------------- 当他们点击单元格时,他们会被推到一个新屏幕上,在那里他们会填写一些文本视图(可能嵌入到tableview的单元格中) 然后,当他们返回时,他们可以看到新记录以及“添加记录”单元格 --------------- | record
---------------
+ | add record |
---------------
当他们点击单元格时,他们会被推到一个新屏幕上,在那里他们会填写一些文本视图(可能嵌入到tableview的单元格中)
然后,当他们返回时,他们可以看到新记录以及“添加记录”单元格
---------------
| record 1 |
---------------
+ | add record |
---------------
(当他们再次进入记录1时,会有一个删除按钮)
是否有任何示例代码或库可以实现这一点?我认为这项任务非常简单。您不需要任何代码示例。 您只需了解UITableView数据源的工作原理以及UINavigationView的工作原理 阅读以下两个指南:
UITableView
推入带有“添加记录”单元格的UINavigationController
堆栈中。在该单元格的选择事件中,您应该推送另一个UITableView
或您的自定义视图。当用户按下“完成”按钮时,您应该将更改的数据保存到您的模型中,并从UINavigationController
堆栈中提取当前视图。之后,您应该告诉您的第一个UITableView
模型已更改,它将再次读取该模型
对评论的回答
你应该设计你的数据结构。例如,您的模型将是MyRecord对象的NSMutableArray。因此,您可以签入表视图:cellforrowatinexpath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]
autorelease];
}
if[recordsArray count] > 0 {
// you have some records
if(indexPath.row < [recordsArray count]) {
MyRecord *record = [recordsArray objectAtIndex:indexPath.row];
cell.textLabel.text = record.name;
} else {
// last cell is Add Record
cell.textLabel.text = @"Add Record";
}
} else {
cell.textLabel.text = @"Add Record";
}
return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell*单元格=[tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
单元格=[[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]
自动释放];
}
如果[recordsArray count]>0{
//你有一些记录
if(indexath.row<[recordsArray计数]){
MyRecord*record=[recordsArray objectAtIndex:indexPath.row];
cell.textlab.text=record.name;
}否则{
//最后一个单元格是添加记录
cell.textlab.text=@“添加记录”;
}
}否则{
cell.textlab.text=@“添加记录”;
}
返回单元;
}
这只是一个想法。它可能包含一些愚蠢的东西(如2个硬编码的@“添加记录”),但想法应该很清楚您可以始终使用ADC网站上的tableView示例,但您尝试过什么吗?这通常是理解东西是如何工作的最好方法…:)谢谢你。我熟悉推送视图和UITableView等,但不清楚如何将数据从第二个表保存并传递回初始表?谢谢如何将该记录从第二个表传递到第一个表?我想我理解了如何从第一个视图传递到第二个视图(在第二个视图中为数据创建属性,然后在进入第二个视图之前在第一个viewcontroller中设置它们)。。。。但我不确定如何将数据从第二个视图传递到第一个视图。如果属性为“保留”类型(非复制),则第二个视图中所做的所有更改将在第一个视图中可用,因为它将是同一个对象。有几种方法可以做到这一点@属性(保留,非原子)就是其中之一。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]
autorelease];
}
if[recordsArray count] > 0 {
// you have some records
if(indexPath.row < [recordsArray count]) {
MyRecord *record = [recordsArray objectAtIndex:indexPath.row];
cell.textLabel.text = record.name;
} else {
// last cell is Add Record
cell.textLabel.text = @"Add Record";
}
} else {
cell.textLabel.text = @"Add Record";
}
return cell;
}