我刚开始在 Xcode 4.3 中使用 Master-Detail 视图模板,我正在尝试更改 master 的背景颜色并将其设置为颜色渐变。这是我尝试过的:
颜色.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
主视图控制器.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;
}
运行时出现以下错误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]));
}
}
我也将 QuartzCore 框架添加到项目中。我在这里错过了什么?当发生此类错误时,我通常应该往哪个方向发展(因为构建成功,应用程序似乎在这里崩溃了)?