我在自己的应用程序中有一个窗体,存在于带有自定义单元格的UITableView
之外。这些单元格可以包含UITextField
,UISegmentedControl
或UISwitch
。这是我此设置:带有自定义UITableViewCells的窗体
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableViewInner cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DetailTableViewCell *cell;
static NSString *MyIdentifier = @"MyIdentifier";
DetailTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[DetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
[cell setTextField:@"John Appleseed"];
// or
[cell setSegment];
[cell setSegmentIndex:1];
// or
[cell setSwitch];
[cell setSwitchEnabled:YES];
return cell;
}
现在,当用户点击保存按钮,我需要获取所有信息,并init
与它的模型,就像这样:
[[Restaurant alloc] initWithName:@"Name here" withNotifications:1 withFrequency:1 withDate:@"Date here" andWithDistance:@"Distance here"];
有什么最好和最干净的方式可能将所有这些输入转换为我模型中的数据?我觉得循环所有的单元格有点过分。
实际代码例如:http: //www.apeth.com/iOSBook/ch21.html#_editable_content_in_table_items – matt
我哈哈我也有说:我不太喜欢Save架构。用户不希望必须点击保存才能使其更改保持不变。他们希望他们的变化能够在他们做出自动保存时自动保存。这就是我的书籍例子的行为。 – matt