I have a UITableView with this code below:
- (UITableViewCell *)tableView:(UITableView *)tableViews cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
TableViewCell *cell = [tableViews dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (indexPath.row == 0){
cell.image.image = [UIImage imageNamed:@"male80.png"];
cell.text.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Phone" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}
if(indexPath.row == 1) {
cell.image.image = [UIImage imageNamed:@"male80.png"];
cell.text.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Mobile Phone" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}
if (indexPath.row == 2) {
cell.image.image = [UIImage imageNamed:@"gift41.png"];
cell.text.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"E-mail" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}
if (indexPath.row == 3) {
cell.image.image = [UIImage imageNamed:@"gender.png"];
cell.text.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"address" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}
if (indexPath.row == 4) {
cell.image.image = [UIImage imageNamed:@"gender.png"];
cell.text.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"country" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}
if (indexPath.row == 5) {
cell.image.image = [UIImage imageNamed:@"gender.png"];
cell.text.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"city" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}
if (indexPath.row == 6) {
cell.image.hidden = YES;
cell.text.hidden = YES;
UITextView *view = [[UITextView alloc] initWithFrame:CGRectMake(15, 10, cell.frame.size.width - 18, cell.frame.size.height - 15)];
view.text = @"Text Example";
view.textColor = [UIColor whiteColor];
view.backgroundColor = [UIColor clearColor];
view.tag = 13;
view.layer.borderWidth = 0.5f;
view.layer.cornerRadius = 4;
view.layer.borderColor = [[UIColor grayColor] CGColor];
[cell addSubview:view];
}
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row != 6) {
return 65;
}else{
return 204;
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 7;
}
This code is very simple, the problem with him is:
- When I run my app first time, I can see my fields organized in the manner prescribed (Like I put in cellforRowAtIndexPath)
- When I scroll down (put my fields out of window) and scroll to up again I see a problem!
The problem is that my table, create a UITextview in rows like 0, 1 and 2. But why this is happening? in my code I made it clear! That only the row 6 will be created a UITextView!
How can I solve this problem?