A UIImageView category has been defined in HDScrollview.h
. It is not imported in GoodDetailViewController.m
, But when the code cell = [[[NSBundle mainBundle] loadNibNamed: CellIdentifier owner: self options: nil] lastObject];
runs, -(id)initWithCoder:(NSCoder *)aDecoder
in HDScrollview.m
will get called.
What's going on here? Any help will be appreciated.
ps.
HDScrollview.h
is imported in GoodDetailViewController.m
but not in GoodDetailViewController.h
GoodsListViewController.m
...
#import "GoodDetailViewController.h"
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == _mutableArrayGoods.count) {
return [self setLoadMoreCell];
}
static NSString *CellIdentifier = @"TableViewCellGoods";
TableViewCellGoods *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed: CellIdentifier owner: self options: nil] lastObject];
[cell initGoodsCellDefaultStyle];
}
// Configure the cell...
if ( indexPath.row < _mutableArrayGoods.count ) {
Good *good = [_mutableArrayGoods objectAtIndex: indexPath.row];
cell.good = good;
cell.delegate = self;
}
return cell;
}
HDScrollview.h
#import <UIKit/UIKit.h>
#import "HdPageControl.h"
@protocol HDScrollviewDelegate <NSObject>
-(void)TapView:(int)index;
@end
@interface HDScrollview : UIScrollView<UIScrollViewDelegate>
@property (nonatomic,strong) HdPageControl *pagecontrol;
@property (nonatomic,assign) NSInteger currentPageIndex;
@property (assign,nonatomic) id<HDScrollviewDelegate> HDdelegate;
-(id)initWithFrame:(CGRect)frame withImageView:(NSMutableArray *)imageview;
-(id)initLoopScrollWithFrame:(CGRect)frame withImageView:(NSMutableArray *)imageview;
-(void)HDscrollViewDidScroll;
-(void)HDscrollViewDidEndDecelerating;
@end
@interface UIImageView (CopyImageview)<NSCoding>
@end
HDScrollview.m
...
@implementation UIImageView (CopyImageview)
-(void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.backgroundColor forKey:@"backgroundColor"];
[aCoder encodeObject:self.image forKey:@"image"];
[aCoder encodeInt:self.contentMode forKey:@"contentMode"];
[aCoder encodeInt:self.subviews.count forKey:@"subviewscount"];
for(int i=0;i<self.subviews.count;i++)
{
UIView *view=self.subviews[i];
[aCoder encodeObject:view forKey:[NSString stringWithFormat:@"view%d",i]];
}
}
-(id)initWithCoder:(NSCoder *)aDecoder
{
if (self=[super init]) {
self.backgroundColor=[aDecoder decodeObjectForKey:@"backgroundColor"];
self.image=[aDecoder decodeObjectForKey:@"image"];
self.contentMode=[aDecoder decodeIntForKey:@"contentMode"];
int subviewscount=[aDecoder decodeIntForKey:@"subviewscount"];
for(int i=0;i<subviewscount;i++)
{
UIView* view=[aDecoder decodeObjectForKey:[NSString stringWithFormat:@"view%d",i]];
[self addSubview:view];
}
}
return self;
}
@end
...