我正在制作一个iphone应用程序,其中我在第一个单元格中创建输入字段,所以问题是,当应用程序加载时,它在tableView中的文本字段下面显示一行我想要删除该行,如果我们添加新行然后它不显示行,但当行为1时,它显示行。我还附加了应用程序的屏幕截图。
-(UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
// cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"tabelsales.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
//cell.backgroundColor = [UIColor clearColor];
}
for (UIView *subView in cell.subviews)
{
if (subView.tag == 2 || subView.tag == 22)
{
[subView removeFromSuperview];
}
}
tableView.backgroundView=nil;
if(indexPath.section==0){
tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(0,2,248,30)];
tagInputField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
tagInputField.textAlignment=UITextAlignmentLeft;
tagInputField.backgroundColor=[UIColor whiteColor];
tagInputField.tag = 2;
tagInputField.delegate = self;
tagInputField.clearButtonMode = UITextFieldViewModeWhileEditing;
//[self.tableView setSeparatorColor:[UIColor clearColor]];
//[tagInputField setBorderStyle:UITextBorderStyleRoundedRect];
tagInputField.font=[UIFont fontWithName:@"Myriad-Pro" size:8];
[tagInputField setText:@"Enter tag here "];
tagInputField.textColor =[UIColor grayColor];
[cell addSubview:tagInputField];
if(tagArray.count >0)
{
// [tagInputField setBorderStyle:UITextBorderStyleNone];
}
else {
// [tagInputField setBorderStyle:UITextBorderStyleRoundedRect];
}
return cell;
}
if(indexPath.section==1) {
UIButton *crossButton =[[UIButton alloc]initWithFrame:CGRectMake(228, 8, 18, 18)];
crossButton.tag = 22; //use a tag value that is not used for any other subview
//crossButton.backgroundColor = [UIColor purpleColor];
crossButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Cross.png"]];
[cell addSubview:crossButton];
cell.textLabel.font =[UIFont fontWithName:@"Myriad-Pro" size:8];
cell.textLabel.textColor =[UIColor grayColor];
cell.backgroundColor=[UIColor whiteColor];
cell.textLabel.text =[tagArray objectAtIndex:indexPath.row];
[crossButton addTarget:self action:@selector(deleteCell:) forControlEvents:UIControlEventTouchUpInside];
[tagInputField setBorderStyle:UITextBorderStyleNone];
[tagInputField setFrame:CGRectMake(8,2,240,32)];
tableView.backgroundColor=[UIColor whiteColor];
[publishButton setFrame:CGRectMake(40,560,250, 50)];
[descriptionTextImageView setFrame:CGRectMake(48,450,250,90)];
return cell;
}
答案 0 :(得分:0)
如果您不使用页脚,可以在页脚中添加一个空视图。
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] init];
return view;
}
另一种选择是使用UITableViewStyleGrouped样式。
-Cong