当时在项目中完成的效果是,我在Footer中放了一个按钮,能动态生成行,并且绑定相应的文本框和删除按钮
下面实现该效果:
//setting section of number
- (NSInteger)numberOfSectionsInTableV
*)tableView
{
1;
}
//返回视图行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
[arrayRow count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
* nul = [NSString stringWithFormat:@"cell%d",indexPath.row];
*Cell = [tableView dequeueReusableCellWithI
= UITableViewCellAccessory
= UITextAlignmentLeft;
== nil){
= [[[UITableViewCell alloc] initWithFrame:CGRectZero
autorelease];
a Text
*textEmail = [[UITextField alloc] initWithFrame:CGRectMake(30, 10, 231, 31)];
= @"input E-mail";
= [ UIFont systemFontOfSize:14 ];
= UIKeyboardTypeEmailAddre
= indexPath.row;
addTarget:self action:@selector(cancelKeyBoard:) forControlEvents:UIControlEventEditingDid
a button
*btn = [UIButton buttonWithType:UIButtonTypeCustom];
= UIViewContentModeScaleTo
*img = [UIImage imageNamed:@"BAG.png"];
setBackgroundImage:img forState:UIControlStateNormal];
setTitle:@"Button Title" forState:UIControlStateNormal];
setTag:[indexPath row]];
addTarget:self action:@selector(deletePressed:)
= CGRectMake(261, 10, 20, 20);
addSubview:textEmail];
addSubview:btn];
= UITableViewCellSelection
release];
Cell;
}
UIButton *addBtn;
//add row in tableview and datasourse
- (IBAction) addPressed:(id)sender
{
= (UIButton*)sender;
addObject:@"Add"];
([arrayRow count] ==4) {
setHidden:YES];
* indexPath = [NSIndexPath indexPathForRow:[arrayRow count]-1 inSection:0];
insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationF
}
//delete row in tableview and datasourse
-(void)deletePressed:(id)sender
{
([arrayRow count] ==1) {
([arrayRow count] <= 4) {