This is to explain why only levels2view is shown.
Up vote 0 down vote favorite share g+ share fb share tw.
I got this code from the apple sample project scrolling: @synthesize scrollView1, scrollView2; const CGFloat kScrollObjHeight = 467.0; const CGFloat kScrollObjWidth = 320.0; const NSUInteger kNumImages = 6; - (void)layoutScrollImages { UIImageView *view = nil; NSArray *subviews = scrollView1 subviews; // reposition all image subviews in a horizontal serial fashion CGFloat curXLoc = 0; for (view in subviews) { if (view isKindOfClass:UIImageView class && view. Tag > 0) { CGRect frame = view. Frame; frame.
Origin = CGPointMake(curXLoc, 0); view. Frame = frame; curXLoc += (kScrollObjWidth); } } // set the content size so it can be scrollable scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), scrollView1 bounds.size. Height); } I tried to modify this to load subviews instead of images but it doesn't work.
I think I'm somehow replacing the views instead of adding them? I need to load the views from separate xib files, and scroll left to right through the xib's (they each contain a panel of buttons leading to different levels in my game). So what am I doing wrong?
Why doesn't this work? It only ever shows the second panel and whenever I push a button it crashes with a SIGABRT. #import "LevelSelectButtons.
H" @implementation LevelSelectButtons @synthesize levelScroll; const int kScrollObjHeight = 400; const int kScrollObjWidth = 320; const NSUInteger kNumCategories = 5; - (void)layoutScrollScreens { UIImageView *view = nil; NSArray *subviews = levelScroll subviews; // reposition all image subviews in a horizontal serial fashion CGFloat curXLoc = 0; for (view in subviews) { if (view isKindOfClass:UIImageView class && view. Tag > 0) { CGRect frame = view. Frame; frame.
Origin = CGPointMake(curXLoc, 0); view. Frame = frame; curXLoc += (kScrollObjWidth); } } // set the content size so it can be scrollable levelScroll setContentSize:CGSizeMake((kNumCategories * kScrollObjWidth), levelScroll bounds.size. Height); } - (void)viewDidLoad { levelScroll setScrollEnabled:YES; CGFloat width = 640; //kScrollObjWidth*kNumCategories; CGFloat height = 400; levelScroll setContentSize:CGSizeMake(width, height); self.
View addSubview:levelScroll; levelScroll. PagingEnabled = YES; levelScroll. IndicatorStyle = UIScrollViewIndicatorStyleWhite; levelScroll.
PagingEnabled = YES; /// LEVELS 1 /// NSUInteger viewNum = 0; CGRect catViewFrame = CGRectMake(0, 0, kScrollObjWidth, kScrollObjHeight); UIView *levels1view = UIView alloc initWithFrame:catViewFrame; NSArray *array1 = NSBundle mainBundle loadNibNamed:@"Levels1" owner:self options:nil; levels1view = array1 objectAtIndex:0; levels1view. Tag = viewNum; self. LevelScroll addSubview:levels1view; /// LEVELS 2 /// viewNum = 1; catViewFrame = CGRectMake(320, 0, kScrollObjWidth, kScrollObjHeight); UIView *levels2view = UIView alloc initWithFrame:catViewFrame; NSArray * array2= NSBundle mainBundle loadNibNamed:@"Levels2" owner:self options:nil; levels2view = array2 objectAtIndex:0; levels2view.
Tag = viewNum; self. LevelScroll addSubview:levels2view; self layoutScrollScreens; super viewDidLoad; } This is the line where the SIGABRT appears: int retVal = UIApplicationMain(argc, argv, nil, nil); iphone objective-c xcode ipad link|improve this question asked Jun 12 '11 at 6:08aking63845 100% accept rate.
The sigabrt usually is an NSAssert kicking in. Look closer at the console, isnt there more information above that SIGABORT line? – Till Jun 12 '11 at 6:13 Can you provide the crash logs?
– Deepak Jun 12 '11 at 6:45.
This is to explain why only levels2view is shown. /// LEVELS 2 /// viewNum = 1; catViewFrame = CGRectMake(320, 0, kScrollObjWidth, kScrollObjHeight); UIView *levels2view = UIView alloc initWithFrame:catViewFrame; If you look here, you're creating a new view with the desired frame where you want your levels2view to be positioned. But, NSArray * array2= NSBundle mainBundle loadNibNamed:@"Levels2" owner:self options:nil; levels2view = array2 objectAtIndex:0; levels2view.
Tag = viewNum; self. LevelScroll addSubview:levels2view; Here you're reassigning the variable to a new view and thus losing the reference to the view you created resulting in a memory leak. That aside, this view doesn't have its frame set.
This will default to origin being at CGPointZero. And since you do the same thing with levels1view, you end up positioning levels2view on top of levels1view when you add them to the scroll view when you add them in that order. To remedy this, viewNum = 1; catViewFrame = CGRectMake(320, 0, kScrollObjWidth, kScrollObjHeight); NSArray * array2= NSBundle mainBundle loadNibNamed:@"Levels2" owner:self options:nil; UIView * levels2view = array2 objectAtIndex:0; levels2view.
Frame = catViewFrame; levels2view. Tag = viewNum; self. LevelScroll addSubview:levels2view.
Thanks so much for the tip! But Ive implemented your changes and it still seems to be showing up right ontop of the first. Any thoughts on why that might be?
– aking63 Jun 14 '11 at 6:50.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.