Ich habe gerade mit der Master-Detail-Ansichtsvorlage in Xcode 4.3 begonnen und versuche, die Hintergrundfarbe des Masters zu ändern und auf einen Farbverlauf einzustellen. Hier ist, was ich versucht:iOS UITableView: Hintergrundfarbe als Farbverlauf mit CAGradiantLayer zuweisen
Colors.m
#import "Colors.h"
@implementation Colors
+ (UIColor *) navigationMenuGradientTop
{
return [UIColor colorWithRed:213.0f/255.0f green:91.0f/255.0f blue:92.0f/255.0f alpha:1.0f];
}
+ (UIColor *) navigationMenuGradientBottom
{
return [UIColor colorWithRed:188.0f/255.0f green:0.0f/255.0f blue:1.0f/255.0f alpha:1.0f];
}
+ (CAGradientLayer *) navigationMenuGradient
{
NSArray *colors = [NSArray arrayWithObjects:(id)self.navigationMenuGradientTop, self.navigationMenuGradientBottom, nil];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = colors;
return gradientLayer;
}
@end
MasterViewController.m
import "Colors.h"
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
CAGradientLayer *bgLayer = [Colors navigationMenuGradient];
bgLayer.frame = tableView.bounds;
[tableView.layer insertSublayer:bgLayer atIndex:0];
return cell;
}
Beim Laufen ich die folgende Fehlermeldung in main
-Thread 1: EXC_BAD_ACCESS (code=1, address=0xxxxxxxx)
int main(int argc, char *argv[])
{
@autorelasespool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
I habe das QuartzCore-Framework ebenfalls zum Projekt hinzugefügt . Was vermisse ich hier drüben? und in welche Richtung sollte ich generell gehen, wenn solche Fehler auftreten (weil der Build erfolgreich war, scheint die App hier abgestürzt zu sein)?
möglich Duplikat [Gradients auf UIView und UILabels auf iPhone] (http://stackoverflow.com/questions/422066/gradients-on-uiview-and-uilabels-on-iphone) –