I have a table view with custom cell that contains UITextView, UILabel and a UIButton.
The problem is,
When the table is loaded first time, 2 cells are shown and are fine. but any of the cell get scrolled out of the screen while scrolling the table, app suddenly get terminated without showing any exception error to Console.
this is my code,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"In tableView:Cell");
static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";
CourtsFavoriteCustomCell* cell = (CourtsFavoriteCustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if( cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CourtsFavoriteCustomCell"
owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[CourtsFavoriteCustomCell class]])
cell = (CourtsFavoriteCustomCell *)oneObject;
//*********** Creating button inside each TableView cell..
UIButton *mapButton = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;
[mapButton setFrame:CGRectMake(120.0f, 157.0f, 72.0f, 32.0f)] ;
//btnDetail.backgroundColor = [UIColor grayColor];
[mapButton setTitle:@"Map" forState:UIControlStateNormal];
[mapButton setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
//[mapButton.titleLabel setFont:[UIFont fontWithName:@"Verdana-Bold" size:12]];
[mapButton setBackgroundColor:[UIColor clearColor]];
[mapButton sizeThatFits:mapButton.frame.size];
[cell addSubview:mapButton];
[mapButton addTarget:self
action:@selector(cellMapButtontapped:)
forControlEvents:UIControlEventTouchUpInside];
forState:UIControlStateNormal];
}
NSLog(@"App get terminated after showing this log message to console when scrolling tableview");
cell.name.text = favCourtName; // name is a UIText view and if comment this line of code, every thing works fine
cell.address.text = favCourtAddress;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
I am using UITextView (Cell.name in the code)in my custom cell. When I tried commenting the UITextView code out, then everything works fine.
Please help me 🙂 thanx..
@All, Thanx for all of yours answers.. 🙂
I solved the problem. It was not with UITextView.
And why I am writing here because, If anybody else comes here with the same problem it may help.
Problem was actually very simple, but took my 2 days to find out because it did not show any exceptions.
What I did was, just added the ‘retain’ to my ‘favCourtName’ in my ViewDidLoad method. Its like this,
The word ‘retain’ does the magic. Thank you