 |
 |
|
 |
10-13-2011, 02:35 AM
|
#1 (permalink)
|
|
Registered Member
Join Date: Oct 2011
Posts: 1
|
Questions about the addsubview problem
Hi everyone
I have a problem on the subview that that cannot be shown after addSubview to the self.view or other subview
Code:
#import "VC_B.h"
#define APP_DELEGATE ((RecipeAppDelegate*)[[UIApplication sharedApplication] delegate])
#define NUM_DISHES 8
#define H_IPAD 768
#define W_IPAD 1024
#define H_UPFR 490
#define W_UPFR W_IPAD
#define H_ALPFR 246
#define H_INGREPHOTO 239
#define W_INGREPHOTO 161
#define W_LEFTARROW 40
#define H_LEFTARROW 151
#define W_RIGHTARROW W_LEFTARROW
#define H_RIGHTARROW H_LEFTARROW
#define H_TRANSIT_TO_C 127
#define W_TRANSIT_TO_C 127
#define W_TRANSIT_TO_A 57
#define H_TRANSIT_TO_A 57
#define H_BAR1 28
#define W_NUMBERSTEP 20
#define H_NUMBERSTEP 20
#define UPLEFT_PHOTO (CGRectMake(0, 0, W_IPAD / 2, H_UPFR))
#define UPRIGHT_PHOTO (CGRectMake(W_IPAD / 2, 0, W_IPAD / 2, H_UPFR))
#define FRAME_LOWERPART (CGRectMake(0, 528, W_IPAD, 246))
#define BUT_TRANS_B_TO_A (CGRectMake(7, 7, W_TRANSIT_TO_A, H_TRANSIT_TO_A))
#define BUT_TRANS_B_TO_C (CGRectMake(897, 119, W_TRANSIT_TO_C, H_TRANSIT_TO_C))
#define LEFTARROW (CGRectMake(3, 160, W_LEFTARROW, H_LEFTARROW))
#define RIGHTARROW (CGRectMake(981, 160, W_RIGHTARROW, H_RIGHTARROW))
//(CGRectMake(90, H_UPFR + H_BAR1, 130, H_BAR1))
enum{
ID_BACKGROUND,
ID_MAINVIEW,
ID_LBUTTOM,
ID_RBUTTOM,
ID_TRANSIT_TO_A,
ID_ALPHA_BAR,
ID_BAR1,
ID_NUMBERSTEP,
ID_BARLASTNUM,
ID_ALPHA_FRAME,
ID_STEPS,
ID_TRANSIT_TO_C,
ID_INGRED_IMG,
ID_INGRED_AMOUNT,
ID_INGRED_METHOD
};
@implementation VC_B
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//NSArray section
NSArray* ary_img = [NSArray arrayWithObjects:@"whitesugar.png", @"water.png", @"whiteflour.png", @"whitesugar.png", @"water.png", @"whiteflour.png", @"water.png", @"whiteflour.png", nil];
NSArray* ary_amount = [NSArray arrayWithObjects:@"20 g whitesugar", @"30 g whitesugar", @"40 g whitesugar", @"50 g whitesugar", @"60 g whitesugar", @"70 g whitesugar", @"80 g whitesugar", @"90 g whitesugar", nil];
NSArray* ary_meth = [NSArray arrayWithObjects:@"dust", @"slice", @"season", @"add", @"slice", @"season", @"add", @"season", nil];
//NSMutableArray sections
NSMutableArray* ary_image = [[NSMutableArray alloc] initWithCapacity:NUM_DISHES];
NSMutableArray* ary_amt = [[NSMutableArray alloc] initWithCapacity:NUM_DISHES];
NSMutableArray* ary_method = [[NSMutableArray alloc] initWithCapacity:NUM_DISHES];
UIImageView* background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]];
[background setFrame:CGRectMake(0, 0, W_IPAD, H_IPAD)];
UIView* mainview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, W_IPAD, H_IPAD)];
/*
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, W_IPAD, H_IPAD)];
CGSize s = CGSizeMake([scroll frame].size.width * NUM_DISHES, [scroll frame].size.height);
[scroll setContentSize:s];
[scroll setPagingEnabled:TRUE];
UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[scroll addGestureRecognizer:gesture];
*/
[mainview insertSubview:background atIndex:ID_BACKGROUND];
//[scroll setDelegate:self];
//no need to use for loop
UIView* alpha_bar = [[UIView alloc] initWithFrame:CGRectMake(0 + W_IPAD , 492, W_IPAD, 28)];
[alpha_bar setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.3]];
UIView* alphaframe = [[UIView alloc] initWithFrame:CGRectMake(0 + W_IPAD , 522, W_IPAD , H_ALPFR)];
[alphaframe setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.3]];
//left and right press buttom , back2 and steplist
UIImageView* left_buttom = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"left1.png"]];
[left_buttom setFrame:CGRectMake(0, 160, W_LEFTARROW, H_LEFTARROW)];
UIImageView* right_buttom = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right1.png"]];
[right_buttom setFrame:CGRectMake(984, 160, W_RIGHTARROW, H_RIGHTARROW)];
UIImageView* but_transit_to_c = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"steplist1.png"]];
[but_transit_to_c setFrame:CGRectMake(897, 119, W_TRANSIT_TO_C, H_TRANSIT_TO_C)];
UIImageView* but_transit_to_b = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back2.png"]];
[but_transit_to_b setFrame:CGRectMake(7, 7, W_TRANSIT_TO_A, H_TRANSIT_TO_A)];
//alpha bar last num
UILabel* lbl_lastnum = [[UILabel alloc] initWithFrame:CGRectMake(1000, 5, W_NUMBERSTEP, H_NUMBERSTEP)];
[lbl_lastnum setBackgroundColor:[UIColor clearColor]];
[lbl_lastnum setText:@"8"];
[lbl_lastnum setTextColor:[UIColor blackColor]];
[lbl_lastnum setFont:[UIFont systemFontOfSize:20]];
//for loop part
for (int i = 0; i < NUM_DISHES; i++){
UIImageView* img_steps = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i + 1]]];
//IMPORTANT: The i*W_IPAD means that 1st 0*1024 , 1*1024 , 2*1024.............and so on
[img_steps setFrame:CGRectMake(i*W_IPAD, 0, W_IPAD , H_UPFR)];
//call the Utility subclass method cropImage ......
bar1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar1.png"]];
[bar1 setFrame:CGRectMake(128 * (i + 1) - W_IPAD, 0, W_IPAD, H_BAR1)];
//ingredient section
UIImageView* imageset = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[ary_img objectAtIndex:i]]];
[imageset setFrame:CGRectMake(89, 9, H_INGREPHOTO, W_INGREPHOTO)];
[ary_image addObject:imageset];
//ingredient amount section
UILabel* lbl_amt = [[UILabel alloc] initWithFrame:CGRectMake(128, 177, 190, 33)];
[lbl_amt setText:[ary_amount objectAtIndex:i]];
[lbl_amt setFont:[UIFont systemFontOfSize:25]];
[lbl_amt setTextColor:[UIColor blackColor]];
[lbl_amt setBackgroundColor:[UIColor clearColor]];
[ary_amt addObject:lbl_amt];
//method section
UILabel* lbl_method = [[UILabel alloc] initWithFrame:CGRectMake(596, 93, 130, 32)];
[lbl_method setText:[ary_meth objectAtIndex:i]];
[lbl_method setBackgroundColor:[UIColor clearColor]];
[lbl_method setFont:[UIFont systemFontOfSize:30]];
[lbl_method setTextColor:[UIColor blackColor]];
[ary_method addObject:lbl_method];
//alpha bar step number step number section
UILabel* lbl_numberstep = [[UILabel alloc] initWithFrame:CGRectMake(90 + (130 * i), 5, W_NUMBERSTEP, H_NUMBERSTEP)];
[lbl_numberstep setText:[NSString stringWithFormat:@"%d",i + 1]];
[lbl_numberstep setFont:[UIFont systemFontOfSize:20]];
[lbl_numberstep setBackgroundColor:[UIColor clearColor]];
[lbl_numberstep setTextColor:[UIColor blackColor]];
// Section --- Add Subview
[mainview insertSubview:img_steps atIndex:ID_STEPS];
[alpha_bar insertSubview:bar1 atIndex:ID_BAR1];
[alpha_bar insertSubview:lbl_numberstep atIndex:ID_NUMBERSTEP];
[alpha_bar insertSubview:lbl_lastnum atIndex:ID_BARLASTNUM];
[alphaframe insertSubview:[ary_image objectAtIndex:i] atIndex:ID_INGRED_IMG];
[alphaframe insertSubview:lbl_amt atIndex:ID_INGRED_AMOUNT];
[alphaframe insertSubview:lbl_method atIndex:ID_INGRED_METHOD
];
//self.view section
}
/*position problem
------> if put this paragraph in front of the for loop , then the left button and right button cannot be shown
*/
[self.view insertSubview:mainview atIndex:ID_MAINVIEW];
[mainview insertSubview:alpha_bar atIndex:ID_ALPHA_BAR];
[mainview insertSubview:alphaframe atIndex:ID_ALPHA_FRAME];
[mainview insertSubview:left_buttom atIndex:ID_LBUTTOM];
[mainview insertSubview:right_buttom atIndex:ID_RBUTTOM];
[mainview insertSubview:but_transit_to_b atIndex:ID_TRANSIT_TO_A];
[alphaframe insertSubview:but_transit_to_c atIndex:ID_TRANSIT_TO_C];
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
It only shows the right , left arrow and the img_ingredient but others including the alpha frame and bar not shown what is the problem on the program?
Last edited by baja_yu; 10-19-2011 at 12:53 AM.
Reason: Code tags!
|
|
|
10-20-2011, 09:59 PM
|
#2 (permalink)
|
|
Registered Member
Join Date: Jan 2009
Posts: 113
|
If you're loading from a nib, why are you doing so much view setup in code?
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 375 |
| 9 members and 366 guests |
| bignoggins, epaga, hussain1982, jcdevelopments, LunarMoon, markolo, omagod, pinacate, skog |
| Most users ever online was 1,387, 04-10-2012 at 04:21 AM. |
» Stats |
Members: 175,643
Threads: 94,110
Posts: 402,860
Top Poster: BrianSlick (7,990)
|
| Welcome to our newest member, Diligent |
|