I am not able to make out whatrs wrong with this piece of code all I am trying to do is use custom table cell ‘AlertCell’ when device is in portrait mode and ‘AlertCellLandScape’ if device is in ‘landscape’ mode.
its saying cell is undeclared and inside the condition check its saying unused cell
static NSString *CellIdentifier1 = @"Cell1";
static NSString *CellIdentifier2 = @"Cell2";
UITableViewCell *cell;
if (isPortraitMode)
{
AlertsTableCell *cell = (AlertsTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
}
else {
AlertsTableCellLandScape *cell = (AlertsTableCellLandScape *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
}
if (cell == nil) {
// cell = [[[AlertsTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if (isPortraitMode) {
cell = [[[AlertsTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
}
else {
cell = [[[AlertsTableCellLandScape alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2] autorelease];
}
}
Please shed some light on this.
Thanks in advance
You could do this instead, you have issues with how you declared the types of the cell, but this should work unless you are accessing the cell-reference outside if-else portrait block.