|
|
|
How to clear this error: Thread 1: EXC_BAD_ACCESS (code=2, address=0x8) |
|
|
|
|
|
|
|
yes sure
.h file
Code (Objective-C)
@protocol MADayViewDataSource, MADayViewDelegate;
@interface Trainer_Profile_Page : UIViewController{
UIImageView *_topBackground;
UIButton *_leftArrow, *_rightArrow;
UILabel *_dateLabel;
unsigned int _labelFontSize;
UIFont *_regularFont;
UIFont *_boldFont;
NSDate *day1;
UISwipeGestureRecognizer *_swipeLeftRecognizer, *_swipeRightRecognizer;
id<MADayViewDataSource> __unsafe_unretained _dataSource;
id<MADayViewDelegate> __unsafe_unretained _delegate;
}
@property (readwrite,assign) unsigned int labelFontSize;
@property (nonatomic,copy) NSDate *day;
@property (nonatomic,unsafe_unretained) IBOutlet id<MADayViewDataSource> dataSource;
@property (nonatomic,unsafe_unretained) IBOutlet id<MADayViewDelegate> delegate;
@end
.m file
Code (Objective-C)
#import "Trainer_Profile_Page.h"
#import <QuartzCore/QuartzCore.h>
static NSString *TOP_BACKGROUND_IMAGE = @"ma_topBackground.png";
static NSString *LEFT_ARROW_IMAGE = @"ma_leftArrow.png";
static NSString *RIGHT_ARROW_IMAGE = @"ma_rightArrow.png";
static const unsigned int ARROW_LEFT = 100;
static const unsigned int ARROW_RIGHT = 101;
static const unsigned int ARROW_WIDTH = 48;
static const unsigned int ARROW_HEIGHT = 38;
static const unsigned int TOP_BACKGROUND_HEIGHT = 95;
//#define DATE_COMPONENTS (NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit)
#define CURRENT_CALENDAR [NSCalendar currentCalendar]
#define DATE_COMPONENTS (NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit)
@interface Trainer_Profile_Page ()
- (void)changeDay:(UIButton *)sender;
- (NSDate *)nextDayFromDate:(NSDate *)date;
- (NSDate *)previousDayFromDate:(NSDate *)date;
@property (readonly) UIImageView *topBackground;
@property (readonly) UIButton *leftArrow;
@property (readonly) UIButton *rightArrow;
@property (readonly) UILabel *dateLabel;
@property (readonly) UIFont *regularFont;
@property (readonly) UIFont *boldFont;
@property (readonly) NSString *titleText;
@end
@implementation Trainer_Profile_Page
@synthesize labelFontSize=_labelFontSize;
@synthesize delegate=_delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)viewWillAppear:(BOOL)animated
{
[[self navigationController] setNavigationBarHidden:YES animated:NO];
}
- (UIImageView *)topBackground {
if (!_topBackground) {
_topBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:TOP_BACKGROUND_IMAGE]];
}
return _topBackground;
}
- (UIButton *)leftArrow {
if (!_leftArrow) {
_leftArrow = [UIButton buttonWithType:UIButtonTypeCustom];
_leftArrow.tag = ARROW_LEFT;
[_leftArrow setImage:[UIImage imageNamed:LEFT_ARROW_IMAGE] forState:0];
[_leftArrow addTarget:self action:@selector(changeDay:) forControlEvents:UIControlEventTouchUpInside];
}
return _leftArrow;
}
- (UIButton *)rightArrow {
if (!_rightArrow) {
_rightArrow = [UIButton buttonWithType:UIButtonTypeCustom];
_rightArrow.tag = ARROW_RIGHT;
[_rightArrow setImage:[UIImage imageNamed:RIGHT_ARROW_IMAGE] forState:0];
[_rightArrow addTarget:self action:@selector(changeDay:) forControlEvents:UIControlEventTouchUpInside];
}
return _rightArrow;
}
- (UILabel *)dateLabel {
if (!_dateLabel) {
_dateLabel = [[UILabel alloc] init];
_dateLabel.textAlignment = NSTextAlignmentCenter;
_dateLabel.backgroundColor = [UIColor clearColor];
_dateLabel.font = [UIFont boldSystemFontOfSize:18];
_dateLabel.textColor = [UIColor colorWithRed:59/255. green:73/255. blue:88/255. alpha:1];
}
return _dateLabel;
}
- (void)setDataSource:(id <MADayViewDataSource>)dataSource {
_dataSource = dataSource;
//[self reloadData];
}
- (id <MADayViewDataSource>)dataSource {
return _dataSource;
}
- (void)setDay:(NSDate *)date {
NSDateComponents *components = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:date];
day1 = [CURRENT_CALENDAR dateFromComponents:components];
self.dateLabel.text = [self titleText];
// NSLog(@"%@",self.dateLabel.text);
// [self reloadData];
}
- (NSDate *)day {
NSDate *date = [day1 copy];
return date;
}
- (void)changeDay:(UIButton *)sender {
NSLog(@"day1: %@",day1);
if (ARROW_LEFT == sender.tag) {
self.day = [self previousDayFromDate:day1];
} else if (ARROW_RIGHT == sender.tag) {
self.day = [self nextDayFromDate:day1];
}
}
- (NSDate *)nextDayFromDate:(NSDate *)date {
NSDateComponents *components = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:date];
[components setDay:[components day] + 1];
return [CURRENT_CALENDAR dateFromComponents:components];
}
- (NSDate *)previousDayFromDate:(NSDate *)date {
NSDateComponents *components = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:date];
[components setDay:[components day] - 1];
return [CURRENT_CALENDAR dateFromComponents:components];
}
- (NSString *)titleText {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy"];
return [NSString stringWithFormat:@"%@",
[formatter stringFromDate:day1]];
}
- (void)viewDidLoad
{
self.rightArrow.frame = CGRectMake(280, 60, 20, 20);
[self.view addSubview:_rightArrow];
self.leftArrow.frame = CGRectMake(10, 60, 20, 20);
[self.view addSubview:_leftArrow];
self.day = [NSDate date];
[self.view addSubview:_dateLabel];
self.dateLabel.frame = CGRectMake(60, 0, 200, 150);
self.topBackground.frame = CGRectMake(0, 0, 320, 45);
[self.view addSubview:_topBackground];
[super viewDidLoad];
}
@end
exc_bad_access coming here
Code (Objective-C)
- (void)changeDay:(UIButton *)sender {
NSLog(@"day1: %@",day1);
if (ARROW_LEFT == sender.tag) {
self.day = [self previousDayFromDate:day1];
} else if (ARROW_RIGHT == sender.tag) {
self.day = [self nextDayFromDate:day1];
}
}
|
|
|
|
|
Date :
2013-08-19 19:43:15 |
By :
vishwa |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|