這個僞可能是一個起點:
// define an NSMutableArray called fields
- (IBAction)addField:(id)sender {
// create a new text field here and add it to the array
// then reload data
}
- (IBAction)save:(id)sender {
for(UITextField *textField in fields) {
// whatever you have to do
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// you have as many rows as textfields
return [fields count];
}
- (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];
}
// Set up the cell...
// For row N, you add the textfield N to the array.
[cell addSubview:(UITextField *)[fields objectAtIndex:indexPath.row]];
}
謝謝你們..我知道這是一個有點含糊......但他真的幫了,我也對我的方式。謝謝 –
我覺得你更願意在'if(cell == nil)'塊中調用'cell addSubview',所以每次單元被重用時都不會添加它。 – drewish