How to initialize UIColor from RGB values properly? - uibutton

I am working on an iPhone application which uses various colors. When user selects the particular color button I set drawing color accordingly. I am getting the color for some but in the most of the cases I am getting white color.
Here is my code:
-(IBAction)colorSelected:(UIButton *)sender
{
switch (sender.tag)
{
case 1:
self.drawcolor= [UIColor colorWithRed:200 green:191 blue:231 alpha:1];
break;
case 2:
self.drawcolor= [UIColor colorWithRed:163 green:73 blue:164 alpha:1];
break;
case 3:
self.drawcolor= [UIColor colorWithRed:112 green:146 blue:76 alpha:1];
break;
case 4:
self.drawcolor= [UIColor colorWithRed:63 green:72 blue:204 alpha:1];
break;
case 5:
self.drawcolor= [UIColor colorWithRed:153 green:217 blue:234 alpha:1];
break;
case 6:
self.drawcolor= [UIColor colorWithRed:0 green:162 blue:232 alpha:1];
break;
case 7:
self.drawcolor= [UIColor colorWithRed:181 green:230 blue:29 alpha:1];
break;
case 8:
self.drawcolor= [UIColor colorWithRed:34 green:177 blue:76 alpha:1];
break;
case 9:
self.drawcolor= [UIColor colorWithRed:239 green:228 blue:176 alpha:1];
break;
case 10:
self.drawcolor= [UIColor colorWithRed:255 green:201 blue:0 alpha:1];
break;
case 11:
self.drawcolor= [UIColor colorWithRed:255 green:201 blue:14 alpha:1];
break;
case 12:
self.drawcolor= [UIColor colorWithRed:237 green:28 blue:36 alpha:1];
break;
case 13:
self.drawcolor= [UIColor colorWithRed:255 green:127 blue:39 alpha:1];
break;
case 14:
self.drawcolor= [UIColor colorWithRed:255 green:174 blue:201 alpha:1];
break;
case 15:
self.drawcolor= [UIColor colorWithRed:185 green:122 blue:87 alpha:1];
break;
case 16:
self.drawcolor= [UIColor colorWithRed:136 green:0 blue:21 alpha:1];
break;
case 17:
self.drawcolor= [UIColor colorWithRed:195 green:195 blue:195 alpha:1];
break;
case 18:
self.drawcolor= [UIColor colorWithRed:127 green:127 blue:127 alpha:1];
break;
case 19:
self.drawcolor= [UIColor colorWithRed:255 green:255 blue:255 alpha:1];
break;
case 20:
self.drawcolor= [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
break;
default:
break;
}
self.preColor=self.drawcolor;
self.lineWidth=self.prelineWidth;
}
Can any one tell me what I am doing wrong ?
Sumit

The values are in the 0.0 to 1.0 range.
E.g. divide by 255., but remember the decimal dot so you get floating point division and not integer division.
Like
selectedColor = [UIColor colorWithRed:14.0/255.0 green:114.0/255.0 blue:199.0/255.0 alpha:1];

Pragmatic approach with Swift.
extension UIColor {
convenience init(rgbColorCodeRed red: Int, green: Int, blue: Int, alpha: CGFloat) {
let redPart: CGFloat = CGFloat(red) / 255
let greenPart: CGFloat = CGFloat(green) / 255
let bluePart: CGFloat = CGFloat(blue) / 255
self.init(red: redPart, green: greenPart, blue: bluePart, alpha: alpha)
}
}

You got several options
Code
CGFloat red = 16.0;
CGFloat green = 97.0;
CGFloat blue = 5.0;
CGFloat alpha = 255.0;
UIColor *color = [UIColor colorWithRed:(red/255.0) green:(green/255.0) blue:(blue/255.0) alpha:(alpha/255.0)];
Color picker plugin for Interface Builder
There's a nice color picker from Panic which works well with IB: http://panic.com/~wade/picker/
Xcode plugin
This one gives you a GUI for choosing colors: http://www.youtube.com/watch?v=eblRfDQM0Go
Pods and libraries
There's a nice pod named MPColorTools: https://github.com/marzapower/MPColorTools

Here is a method that you can easily turn into a category on UIColor that will allow you to specify a color based on RGBA values of 0 - 255.
+ (UIColor *)colorFromRGBAWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha {
return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha/255.0];
}
If you make it a UIColor category extension, you can use it like so:
UIColor *myAwesomeColor = [UIColor colorFromRGBAWithRed:48 green:119 blue:167 alpha:255];

In Swift you can easily set your Background-Color for example of a cell like this:
cell.backgroundColor = UIColor.init(red: 14.0/255.0, green: 114.0/255.0, blue: 199.0/255.0, alpha: 1)
:-)

(ContentView.Layer.BorderColor) //CG Object
= UIColor.LightGray.CGColor;

Related

UICollectionViewCell background color not working in iOS 15

I have UICOllectionViewCell and I was using setSelectedMethod to determine which background color I have to show. It is working fine in iOS 14 but in iOS 15 it's not working. Here is the code
- (void)setSelected:(BOOL)selected {
if (selected) {
self.layer.borderColor = [UIColor colorWithWhite:1 alpha:0.5].CGColor;
self.layer.borderWidth = 2.0f;
self.textLabel.textColor = [UIColor whiteColor];
self.backgroundColor = kAppDefaultThemeColor;
}
else{
self.layer.borderColor = kAppDefaultThemeColor.CGColor;
self.layer.borderWidth = 2.0f;
self.textLabel.textColor = [UIColor blackColor];
self.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
}
}

border color of uisegmentedcontrol

I am having trouble changing the border color of my segmented control in iOS7. I found the follow suggestions elsewhere on stackoverflow:
[[UISegmentedControl appearance] setTitleTextAttributes:#{
UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0],
UITextAttributeFont: [UIFont fontWithName:#"Arial-Bold" size:0.0],
NSForegroundColorAttributeName : [UIColor redColor],
} forState:UIControlStateSelected];
[self.segmentedControl setTitleTextAttributes:#{
UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0],
UITextAttributeFont: [UIFont fontWithName:#"Arial-Bold" size:0.0],
NSForegroundColorAttributeName : [UIColor redColor],
} forState:UIControlStateNormal];
But in both cases, my border is still a blue color. I can't seem to change the font shadow, the border color or anything else via the settitleTextAttributes.
How do i adjust the border color?
[segmentControlObj setTintColor:[UIColor redColor]];
Ok I struggled way too much with this. So I did a work around. i ended up just creating a new UILabel and add it as subview to each of the items in the segmented controller.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
NSArray * segments = #[#"Crop",#"Nutrient",#"Product Group"];
[self.segmentedControl setBackgroundImage:[UIImage imageNamed:#"background-yellowgradient.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self.segmentedControl setSegmentedControlStyle:UISegmentedControlStyleBar];
for (int i=0; i<[self.segmentedControl.subviews count]; i++)
{
[[self.segmentedControl.subviews objectAtIndex:i] setTintColor:[UIColor clearColor]];
UILabel *l = [[UILabel alloc] init];
l.text = [segments objectAtIndex:i];
l.textColor = [UIColor whiteColor];
l.textAlignment = NSTextAlignmentCenter;
l.adjustsFontSizeToFitWidth = NO;
l.font = [UIFont systemFontOfSize:12];
CGRect f = [[self.segmentedControl.subviews objectAtIndex:0] frame];
f.size.width = self.segmentedControl.frame.size.width/3;
f.size.height = self.segmentedControl.frame.size.height;
f.origin.x = 0;
f.origin.y = 0;
l.frame = f;
[[[self.segmentedControl subviews] objectAtIndex:i] addSubview:l];
}
}
else{
// if it's not IOS7, then do what i was doing before for ios6.1 and below
}

iOS7 custom UITableViewCell ui objects will not display within UITableViewController

I created a custom UITableViewCell which works perfectly with iOS6, now with iOS7 i only get the standard white background without any of my customized cell UI objects.
I noticed that apple introduce a new view to the UITableView but how i should handle it ?
I tried:
- cell.contentView.backgroundColor = [UIColor clearColor];
within UITableViewController cellForRowAtIndexPath but without effect :(
UITableViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PdfFile *file = [[pdfDS.ditcDocuments objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
int maxCells = [[pdfDS.ditcDocuments objectAtIndex:indexPath.section] count];
MedialoungeDocumentTableViewCell *cell = [[MedialoungeDocumentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"DocumentTableCell"];
[cell setDocumentTitle: file.fileTitle];
[cell setFirstElement:(indexPath.row == 0) ? YES:NO];
[cell setLastElement:(indexPath.row == (maxCells -1)) ? YES:NO ];
NSString *subTitle = [file.fileSubtitle isEqualToString:#""]?#"":file.fileSubtitle;
if([file.documentKind isEqualToString: PDFKIND_SUCCESS]){
[cell setDocumentKind:PDFDOCTYPE_SUC];
[cell setDocumentSubtitle:[NSString stringWithFormat:#"%#",subTitle]];
}else if([file.documentKind isEqualToString:PDFKIND_SOLUTION]){
[cell setDocumentSubtitle:[NSString stringWithFormat:#"%#", subTitle]];
[cell setDocumentKind:PDFDOCTYPE_SOL];
}else if([file.documentKind isEqualToString:PDFKIND_RESEARCH]){
[cell setDocumentSubtitle:[NSString stringWithFormat:#"%#", subTitle]];
[cell setDocumentKind:PDFDOCTYPE_WP];
}
cell.contentView.backgroundColor = [UIColor clearColor];
return cell;
}
My custom UITableViewCell:
- (void)drawContentView:(CGRect)rect highlighted:(BOOL)highlighted {
//// Color Declarations
UIColor* grey = [UIColor colorWithRed: 0.178 green: 0.178 blue: 0.178 alpha: 1];
UIColor* color4 = [UIColor colorWithRed: 0.611 green: 0.611 blue: 0.611 alpha: 1];
UIColor* color6 = [UIColor colorWithRed: 0.529 green: 0.529 blue: 0.529 alpha: 1];
UIColor* active = CUSTOM_COLOR(62, 62, 62, 1);
//// Abstracted Attributes
NSString* dcoumentTitleContent = self.documentTitle;
NSString* subtitleContent = self.documentSubtitle;
//// background Drawing
UIBezierPath* backgroundPath = [UIBezierPath bezierPath];
[backgroundPath moveToPoint: CGPointMake(8, 60)];
[backgroundPath addLineToPoint: CGPointMake(8, 0)];
[backgroundPath addLineToPoint: CGPointMake(30, 0)];
[backgroundPath addLineToPoint: CGPointMake(930.00, 0)];
if(lastElement){
[backgroundPath addLineToPoint: CGPointMake(930.00, 50.00)];
}else{
[backgroundPath addLineToPoint: CGPointMake(930.00, 60.00)];
}
[backgroundPath addLineToPoint: CGPointMake(920, 60)];
[backgroundPath addLineToPoint: CGPointMake(8, 60)];
[backgroundPath closePath];
if(highlighted){
[active setFill];
}else{
[grey setFill];
}
[backgroundPath fill];
//// colorStripe Drawing
UIBezierPath* colorStripePath = [UIBezierPath bezierPath];
[colorStripePath moveToPoint: CGPointMake(0, 60)];
[colorStripePath addLineToPoint: CGPointMake(0, 0)];
[colorStripePath addCurveToPoint: CGPointMake(10, 0) controlPoint1: CGPointMake(0,0) controlPoint2: CGPointMake(10, 0)];
[colorStripePath addCurveToPoint: CGPointMake(10, 60) controlPoint1: CGPointMake(10, 0) controlPoint2: CGPointMake(10, 60)];
[colorStripePath addLineToPoint: CGPointMake(0, 60)];
[colorStripePath closePath];
if(documentKind == PDFDOCTYPE_SOL){
[CUSTOM_COLOR(SOL_COLOR_R, SOL_COLOR_G, SOL_COLOR_B, SOL_COLOR_A) setFill];
}else if (documentKind == PDFDOCTYPE_SUC){
[CUSTOM_COLOR(SUC_COLOR_R, SUC_COLOR_G, SUC_COLOR_B, SUC_COLOR_A) setFill];
}else if(documentKind == PDFDOCTYPE_WP){
[CUSTOM_COLOR(WP_COLOR_R, WP_COLOR_G, WP_COLOR_B, WP_COLOR_A) setFill];
}
[colorStripePath fill];
//// dcoumentTitle Drawing
CGRect documentTitleRect = CGRectMake(78, 7, 800, 40);
[color4 setFill];
if (SYSTEM_VERSION_LESS_THAN(#"7")){
[dcoumentTitleContent drawInRect: documentTitleRect withFont: [UIFont fontWithName: #"Helvetica-Bold" size: 21.5] lineBreakMode: NSLineBreakByWordWrapping alignment: NSTextAlignmentLeft];
}else{
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle defaultParagraphStyle]mutableCopy];
[style setAlignment:NSTextAlignmentLeft];
[style setLineBreakMode:NSLineBreakByWordWrapping];
CGFloat fontSize = 21.5;
UIFont *font = [UIFont fontWithName:#"Helvetica-Bold" size:fontSize];
NSDictionary *dict=#{
NSFontAttributeName : font,
NSParagraphStyleAttributeName: style
};
[dcoumentTitleContent drawInRect:documentTitleRect withAttributes:dict];
}
//// subtitle Drawing
CGRect subtitleRect = CGRectMake(79, 32, 800, 22);
[color6 setFill];
if (SYSTEM_VERSION_LESS_THAN(#"7")){
[subtitleContent drawInRect: subtitleRect withFont: [UIFont fontWithName: #"Helvetica-Bold" size: 13] lineBreakMode: NSLineBreakByWordWrapping alignment: NSTextAlignmentLeft];
}else{
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle defaultParagraphStyle]mutableCopy];
[style setAlignment:NSTextAlignmentLeft];
[style setLineBreakMode:NSLineBreakByWordWrapping];
CGFloat fontSize = 13.0;
UIFont *font = [UIFont fontWithName:#"Helvetica-Bold" size:fontSize];
NSDictionary *subDict=#{
NSFontAttributeName : font,
NSParagraphStyleAttributeName: style
};
[subtitleContent drawInRect:subtitleRect withAttributes:subDict];
}
UIImage *img= [UIImage imageNamed:#"doc_icon.png"];
[img drawInRect:CGRectMake(35, 10, 28, 40)];
}
Somebody any ideas what i could do?
Screens:
1. so it looks
so it should look like

Trouble with layer.shadowColor and UIColors

Trying to change the color of a shadow. This works:
self.layer.shadowColor = [[UIColor blueColor] CGColor];
but i want to make it a custom color, so i tried:
self.layer.shadowColor = [[UIColor colorWithRed:191/255.0f green:199/255.0f blue:203/255.0f alpha:1] CGColor];
which does not work.
what am i doing wrong?
EDIT:
code snippet from my init method:
self.layer.shadowOpacity = 0;
self.layer.shadowColor = [[UIColor blueColor] CGColor];
//self.layer.shadowColor = [[UIColor colorWithRed:191/255.0f green:199/255.0f blue:203/255.0f alpha:1] CGColor];
self.layer.shadowOffset = CGSizeMake(0,0);
self.layer.shadowRadius = 4;
EDIT 2:
odd part is that i extended UIColor to include some of my custom colors; if i use:
self.layer.shadowColor = [[UIColor pointColorBlue] CGColor];
from my UIColor+myColor:
+(UIColor *) pointColorBlue
{
return [UIColor colorWithRed:50/255.0f green:50/255.0f blue:255/255.0f alpha:1];
}
it works fine.
Bah! figured it out: the graphics guy gave me that RGB value which is nearly identical to the background color!
Those should work.
But you have to do following:
CALayer newLayer = [CALayer layer];
newLayer.shadowColor = [[UIColor blueColor] CGColor];
self.layer = newLayer;
[self.layer setWantsLayer:YES];
It's important to reset the main layer, cause otherways it does not get drawn.

EXC_BAD_ACCESS when I scroll my view

I have two views: the first one is a UITableView in plain style (created programmatically); the second one is a UIScrollView that contains an image and a UITableView in grouped style (also created programmatically).
When I navigate from the firstView -> secondView everything works fine. However if I come back to the firstView and then I try to navigate firstView ->secondView for the second time, I get a EXC_BAD_ACCESS error.
UPDATE
This is the code of the UITableView delegate in the secondView:
-
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case 0:
//header - breve descrizione
return 2;
break;
case 1: //mappa
//header - mappa statica (immagine) - footer (indirizzo)
return 3;
break;
case 2: //review
//header - prima review
return 2;
break;
default:
return 0;
break;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case 0:
switch (indexPath.row) {
case 0: //case titolo (header)
return HTABLE_DESCR_HEADER;
break;
case 1: //case corpo
return HTABLE_DESCR_BODY;
break;
default:
return 0;
break;
}
break;
case 1:
switch (indexPath.row) {
case 0: //case titolo (header)
return HTABLE_LOC_HEADER;
break;
case 1: //case corpo
return HTABLE_LOC_BODY;
break;
case 2: //case footer
return HTABLE_LOC_FOOTER;
break;
default:
return 0;
break;
}
break;
case 2:
switch (indexPath.row) {
case 0: //case titolo (header)
return HTABLE_REV_HEADER;
break;
case 1: //case corpo
return HTABLE_REV_BODY;
break;
default:
return 0;
break;
}
break;
default:
return 0;
break;
}
}
/*- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return #"Travellers Guide";
}*/
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
int section = 2;
//se ci sono review
if ([[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:#"list_review"] count] > 0) {
section++;
}
return section;
}
// 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 = [self getCellContentView:CellIdentifier];
}
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
switch (indexPath.section) {
case 0: //descrizione
switch (indexPath.row) {
case 0: //header
if ([[[NSUserDefaults standardUserDefaults] objectForKey:#"language"] isEqualToString:#"it"]) {
cell.textLabel.text = #"Descrizione";
} else {
cell.textLabel.text = #"Description";
}
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.shadowColor = [UIColor whiteColor];
cell.textLabel.shadowOffset = CGSizeMake(1, 1);
cell.textLabel.highlightedTextColor = [UIColor blackColor];
cell.textLabel.font = [UIFont boldSystemFontOfSize:11.0];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"rigaDescrHeader.png"]];
break;
case 1: //descrizione
NSLog(#"Descr");
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"rigaRevBody.png"]];
cell.textLabel.text = [[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:#"description"];
cell.textLabel.font = [UIFont systemFontOfSize:10.0];
cell.textLabel.lineBreakMode = UILineBreakModeTailTruncation;
cell.textLabel.numberOfLines = 3;
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.shadowColor = [UIColor whiteColor];
cell.textLabel.shadowOffset =CGSizeMake(1, 1);
cell.textLabel.highlightedTextColor = [UIColor blackColor];
break;
default:
break;
}
break;
case 1: //mappa
//header - mappa statica (immagine) - footer (indirizzo)
switch (indexPath.row) {
case 0: //header
if ([[[NSUserDefaults standardUserDefaults] objectForKey:#"language"] isEqualToString:#"it"]) {
cell.textLabel.text = #"Posizione";
} else {
cell.textLabel.text = #"Location";
}
cell.textLabel.font = [UIFont boldSystemFontOfSize:11.0];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.shadowColor = [UIColor whiteColor];
cell.textLabel.shadowOffset = CGSizeMake(1, 1);
cell.textLabel.highlightedTextColor = [UIColor blackColor];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"rigaLocHeader.png"]];
break;
case 1: //mappa
NSLog(#"Mappa");
CLLocationDegrees latitude = [[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:#"latitude"] doubleValue];
CLLocationDegrees longitude = [[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:#"longitude"] doubleValue];
CLLocation* poiLocation = [[[CLLocation alloc] initWithLatitude:latitude longitude:longitude] autorelease];
Annotation *ann = [Annotation annotationWithCoordinate:poiLocation.coordinate];
//mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, HTABLE_LOC_BODY)];
[mapView setHidden:NO];
[mapView addAnnotation:ann];
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = poiLocation.coordinate;
region.span.longitudeDelta = 0.05f;
region.span.latitudeDelta = 0.05f;
[self.mapView setRegion:region animated:YES];
[self.mapView regionThatFits:region];
cell.backgroundView = mapView;
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 302, 120)];
imgView.image = [UIImage imageNamed:#"ombraMappa.png"];
[cell.backgroundView addSubview:imgView];
[imgView release];
break;
case 2: //footer
cell.textLabel.text = [[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:#"locality"];
cell.textLabel.font =[UIFont systemFontOfSize:10.0];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.shadowColor = [UIColor whiteColor];
cell.textLabel.shadowOffset = CGSizeMake(1, 1);
cell.textLabel.highlightedTextColor = [UIColor blackColor];
cell.detailTextLabel.text = [[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:#"address"];
cell.detailTextLabel.font = [UIFont boldSystemFontOfSize:9.0];
cell.detailTextLabel.textColor = [UIColor grayColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.shadowColor = [UIColor whiteColor];
cell.detailTextLabel.shadowOffset = CGSizeMake(1, 1);
cell.detailTextLabel.highlightedTextColor = [UIColor blackColor];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"rigaLocFooter.png"]];
break;
default:
break;
}
break;
case 2: //review
//header - mappa statica (immagine) - footer (indirizzo)
switch (indexPath.row) {
case 0: //header
if ([[[NSUserDefaults standardUserDefaults] objectForKey:#"language"] isEqualToString:#"it"]) {
cell.textLabel.text = [NSString stringWithFormat:#"Recensioni (%d)",[[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:#"list_review"] count]];
} else {
cell.textLabel.text = [NSString stringWithFormat:#"Review (%d)",[[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:#"list_review"] count]];
}
cell.textLabel.font = [UIFont boldSystemFontOfSize:11.0];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.shadowColor = [UIColor whiteColor];
cell.textLabel.shadowOffset = CGSizeMake(1, 1);
cell.textLabel.highlightedTextColor = [UIColor blackColor];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"rigaLocHeader.png"]];
break;
case 1: //review
cell.textLabel.text = [[[[[SingletonCardPOI sharedCardPOI] dicCard] objectForKey:#"list_review"] objectAtIndex:0] objectForKey:#"review"];
cell.textLabel.font =[UIFont systemFontOfSize:10.0];
cell.textLabel.lineBreakMode = UILineBreakModeTailTruncation;
cell.textLabel.numberOfLines = 3;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.shadowColor = [UIColor whiteColor];
cell.textLabel.shadowOffset = CGSizeMake(1, 1);
cell.textLabel.highlightedTextColor = [UIColor blackColor];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"rigaRevBody.png"]];
break;
default:
break;
}
break;
default:
break;
}
return cell;
}
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
return cell;
}
The EXC_BAD_ACCESS isn't caused by the progression of one view to the next. Rather, it will be properties of those views, or the creation and release - or not - of the view objects themselves that are to blame.
Your first step is to run the Analyzer. Then, if you've fixed all that and theres still a problem, start running the Leaks tool in Instruments.
For more details on resolving EXC_BAD_ACCESS issues, along with the excellent link on what causes these errors and step by step instructions for how to fix, have a look at answers to these questions:
finding reason for EXC_BAD_ACCESS - in Xcode4
Random EXC_BAD_ACCESS in a place that it cannot happen
In your case, I'd specifically look at how you are creating secondView, and what you do with firstView when you return to secondView.
I just spent a week tracking down a EXC_BAD_ACCESS problem in a large app that worked fine before converting it to ARC. I would get the EXC_BAD_ACCESS on the closing bracket of a "switch" construct. Yet NSZombieEnabled and the various Instrument settings would not detect anything for me.
What fixed it was putting curlies around the case's that made the difference. I did it for each of them, though perhaps it was critical for only some, i.e.
Before:
case ...:
stmt;
stmt;
break;
After:
case ...:{
stmt;
stmt;
}break;
This fixed the problem in two places within a large app for me. I know that I read something somewhere about ARC and switch/case (and maybe someone can add a link to it), but I don't understand the theory behind why this happened and why this fix worked. Perhaps someone could explain. (Later: after reading the following reference at openradar, it all makes sense --- there is something wrong in the "cleanup code" generated between case statements --- a bogus "release" is generated and that soon causes the EXC_BAD_ACCESS.)
I also discovered this, which might be related: http://openradar.appspot.com/11329693