I am trying to figure out this error from previous 3 hours. By searching, I have come to know that this error is related to memory management, but I have failed to figure out that what I am doing wrong.
I have declared these 4 labels:
@interface InteractiveHistory : UITableViewController {
UILabel *date;
UILabel *startTime;
UILabel *cal;
UILabel *duration;
}
Then created properties and synthesized them. In viewDidLoad, I initialized all like this one:
date = [[UILabel alloc] init];
I also have deallocated them in dealloc() method.
What I want to do is use these 4 labels to write some text in cells of the table. Text will depend upon the indexPath.
In cellForRowAtIndexPath method, just showing you for 2 labels and have indicated error line:
- (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];
NSLog(@"constructing cell");
//set up labels text
date = [NSString stringWithFormat:@"%@",[[int_data objectAtIndex:indexPath.row] objectForKey:@"Date"]];
NSLog(@"%@",date.text); //App crashes at this line
[date setTag:1];
startTime = [NSString stringWithFormat:@"%@",[[int_data objectAtIndex:indexPath.row] objectForKey:@"Start Time"]];
//setting tag and position of label
[startTime setTag:2];
CGRect labelpos = startTime.frame;
labelpos.origin.y = date.bounds.size.height + 2;
startTime.frame = labelpos;
NSLog(@"labels set");
// Configure the cell...
[[cell contentView] addSubview:date];
[[cell contentView] addSubview:startTime];
[[cell contentView] addSubview:duration];
[[cell contentView] addSubview:cal];
NSLog(@"A cell set");
}
return cell;
}
Can anybody plz tell me what am I doing wrong? I hope my Question is clear..
The line:
should be:
Otherwise your
datepointer is set to an instance of an NSString, instead of setting its contents.Edit:
As danh correctly points out, you will have the same problem with
startTime.