Hi guys I'm working in cellForRowAtIndexPath, and I'm trying to embed a textview into the cell. Now, the embedding part is all well and fine, but I am getting the strangest problem when I try and load the textview in all but the first row.
Note: I want The TextView in all but the first row in my table.
The problem is that when I implement an if statement to check for indexpath.row and then scroll down the text view is then NOT visible in some cells. It is somehow related to me having cells with quite large heights >200 and they are initially off screen. When I scroll down it is like the next cell underneath the bottom most visible cell is now responding to a indexpath row of ==0.
I am completely baffled, has anyone any ideas?
My Code
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
CGRect frame; frame.origin.x = 5; frame.origin.y = 10; frame.size.width = 20; frame.size.height = 25;
// ..some unrelated setup in here
//textbox setup
textView = [[UITextView alloc] initWithFrame:CGRectMake(30, 80, 500, 150)];
textView.layer.cornerRadius = 10;
textView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.2];
textView.font = [UIFont fontWithName:@"Helvetica" size:17];
textView.text = @"test-content";
textView.layer.borderWidth = 1;
textView.layer.borderColor = [[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.9] CGColor];
textView.tag = 4;
if (indexPath.row != 0) {
[cell.contentView addSubview:textView];
[textView release];
}
}
// a little more unrelated stuff
return cell;
}
Can someone see the problem?
Thanks