右边是仿左边的界面:
代码下载链接 :点击打开链接
test测试单个页面中出现的问题:
2014-11-23 12:49:27.377 Test[1736:60b] Application tried to push a nil view controller on target <UINavigationController: 0x8da5d50>.
2014-11-23 12:49:29.766 Test[1736:60b] ===¥ 45.00====
2014-11-23 12:49:29.767 Test[1736:60b] -[__NSCFString setText:]: unrecognized selector sent to instance 0x8ddf1e0
<span style="color:#ff0000;">// 实质不是label 而是一个字符串 !!! __NSCFString
同样的错误不要再犯两次!!!!!!</span>
@interface RootViewController : UITabBarController
@end
@impleament
- (void)viewDidLoad
{
[super viewDidLoad];
//底部 tabbar 透明位置的背景色,默认为蓝色,需定制颜色
// 设置 tabbar
[[UITabBar appearance] setTintColor:[UIColor orangeColor]];
NSMutableArray *nvcArr = [NSMutableArray array];
NSArray *classArr = [NSArray arrayWithObjects:@"ShouYeViewController", @"TeMaiViewController",@"10GouViewController", @"YouHuiPinViewController",@"WoDeViewController", nil];
UIViewController *vc = nil;
UINavigationController *nvc = nil;
for (int i = 0; i < classArr.count; i++) {
//根据类名,循环创建图标,省代码!!!
vc = [[NSClassFromString([classArr objectAtIndex:i]) alloc] init];
nvc = [[UINavigationController alloc] initWithRootViewController:vc];
//设置navigationbar
[nvc.navigationBar setBarTintColor:[UIColor orangeColor]];
// 这样设置navigationbar 无效!!!!
//nvc.navigationController.navigationBar.backgroundColor = [UIColor orangeColor];
[nvcArr addObject:nvc];
}
self.viewControllers = nvcArr;
}
@end
// 设置_tableview 分割线的颜色
_tableView.separatorColor = [UIColor clearColor];
内存占用太大的问题:
起初以为是 //cell.model = model; 有问题 ,蓝色部分是问题所在,被修改掉的代码
@implementation TeMaiViewController
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIde = @"cellID";
TeMaiTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIde];
if (!cell) {
cell = [[TeMaiTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIde];
}
TeMaiModel *model = [_modelsArray objectAtIndex:indexPath.row];
<span style="color:#33cc00;">//cell.model = model; //这样设置也不会消耗很多内存,没有创建新的对象,但最好不要这样做</span>
cell.topIconUrl = model.topIconUrl;
cell.topLabelText = model.topLabelText;
cell.topSubLabelText = model.topSubLabelText;
cell.topEndLabelText = model.topEndLabelText;
cell.imagesArray = model.imagesArray;
cell.labelsArray = model.labelsArray;
return cell;
}
@end
@interface TeMaiTableViewCell : UITableViewCell
@property (nonatomic,copy) NSString *topIconUrl;
@property (nonatomic,copy) NSString *topLabelText;
@property (nonatomic,copy) NSString *topSubLabelText;
@property (nonatomic,copy) NSString *topEndLabelText;
@property (nonatomic,retain) NSMutableArray *imagesArray;
@property (nonatomic,retain) NSMutableArray *labelsArray;
<span style="color:#33cc00;">//@property (nonatomic,retain) TeMaiModel *model;</span>
@end
@implementation TeMaiTableViewCell
-(void)setModel:(TeMaiModel *)model
{
<span style="color:#ff0000;">//消耗内存
//_model = [[TeMaiModel alloc] init];</span>
//_model = model;
[_topIconView setImageWithURL:[NSURL URLWithString:model.topIconUrl]];
_topNameLabel.text = model.topLabelText;
float discount = [model.topSubLabelText floatValue]/10;
_topSubLabel.text = [NSString stringWithFormat:@"%.1f折起",discount];
if ([model.topEndLabelText isEqualToString:@"2"]) {
_topEndLabel.text = @"new";
}else{
_topEndLabel.text = @"old";
}
UIImageView *imgView = nil;
UILabel *priceLabel = nil;
for (int i = 0; i < 3; i++) {
if (_imagesArr.count > i) {
NSString *imageName = (i == 0)? @"default_big.jpg":@"default_small.jpg";
imgView = (UIImageView*)[_imagesArr objectAtIndex:i];
[imgView setImageWithURL:[NSURL URLWithString:model.imagesArray[i]] placeholderImage:[UIImage imageNamed:imageName]];
//[imgView setImageWithURL:[NSURL URLWithString:_model.imagesArray[i]]];
priceLabel = (UILabel *)[_imageLabelsArr objectAtIndex:i];
NSString *priceString = [NSString stringWithFormat:@"¥ %@",model.labelsArray[i]];
priceLabel.text = priceString;
}
}
}
@end
尽管注释掉了alloc model 那句,但还是无法解决逐渐加载tableview,内存过大的问题