App is crashing as soon as UITableView gets reloaded
Posted
by
OhhMee
on Stack Overflow
See other posts from Stack Overflow
or by OhhMee
Published on 2011-01-10T04:15:38Z
Indexed on
2011/01/10
5:53 UTC
Read the original article
Hit count: 258
Hello,
I'm developing an app where TableView needs to reload as soon as the login process gets completed. The app crashes with error EXC_BAD_ACCESS
when the table data gets reloaded. It doesn't crash when I remove all case instances except case 0:
What could be the reason behind it?
Here's the code:
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loginDone:)
name:@"loginDone" object:nil];
statTableView.backgroundColor = [UIColor clearColor];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)
section {
return 6;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell.
switch (indexPath.row) {
case 0 :
cell.textLabel.text = @"Foo:";
NSLog(@"%@", data7);
UILabel *myLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 20, 30)];
myLabel2.text = (@"%@", data7);
myLabel2.textColor = [UIColor blackColor];
myLabel2.backgroundColor = [UIColor whiteColor];
myLabel2.font = [UIFont fontWithName:@"Trebuchet MS" size:14];
[cell.contentView addSubview:myLabel2];
break;
case 1:
cell.textLabel.text = @"Foo: ";
UILabel *myLabel4 = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 20, 30)];
myLabel4.text = (@"%@", data11);
myLabel4.textColor = [UIColor blackColor];
myLabel4.backgroundColor = [UIColor whiteColor];
myLabel4.font = [UIFont fontWithName:@"Trebuchet MS" size:14];
[cell.contentView addSubview:myLabel4];
break;
case 2:
cell.textLabel.text = @"Foo: ";
UILabel *myLabel8 = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 20, 30)];
myLabel8.text = (@"%@", data3);
myLabel8.textColor = [UIColor blackColor];
myLabel8.backgroundColor = [UIColor whiteColor];
myLabel8.font = [UIFont fontWithName:@"Trebuchet MS" size:14];
[cell.contentView addSubview:myLabel8];
break;
case 3:
cell.textLabel.text = @"Foo: ";
UILabel *myLabel10 = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 20, 30)];
myLabel10.text = [NSString stringWithFormat:@"%@", data4];
if ([data4 isEqualToString:@"0"]) {
myLabel10.text = @"None";
}
myLabel10.textColor = [UIColor blackColor];
myLabel10.backgroundColor = [UIColor whiteColor];
myLabel10.font = [UIFont fontWithName:@"Trebuchet MS" size:14];
[cell.contentView addSubview:myLabel10];
break;
case 4:
cell.textLabel.text = @"Foo: ";
UILabel *myLabel12 = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 20, 30)];
myLabel12.text = [NSString stringWithFormat:@"%@", data5];
myLabel12.textColor = [UIColor blackColor];
if ([data5 isEqualToString:@"Foo"]) {
myLabel12.textColor = [UIColor redColor];
myLabel12.text = @"Nil";
}
myLabel12.backgroundColor = [UIColor whiteColor];
myLabel12.font = [UIFont fontWithName:@"Trebuchet MS" size:14];
[cell.contentView addSubview:myLabel12];
break;
case 5:
cell.textLabel.text = @"Foo: ";
UILabel *myLabel14 = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 50, 30)];
if ([data6 isEqualToString:@"Foo"]) {
myLabel14.textColor = [UIColor colorWithRed:(0/255.f) green:(100/255.f) blue:(0/255.f) alpha:1.0];
myLabel14.text = @"No Dues";
} else {
myLabel14.text = [NSString stringWithFormat:@"%@", data6];
myLabel14.textColor = [UIColor redColor];
}
myLabel14.backgroundColor = [UIColor whiteColor];
myLabel14.font = [UIFont fontWithName:@"Trebuchet MS" size:14];
[cell.contentView addSubview:myLabel14];
break;
/*
[myLabel2 release];
[myLabel4 release];
[myLabel8 release];
[myLabel10 release];
[myLabel12 release];
[myLabel14 release];
*/
}
return cell;
}
© Stack Overflow or respective owner