If i move the scroll view horizontally it has to show new table with new labels inside it with one question at a time..The number of questions may be 10 or 20..means we have to create new table and new labels every time when scroll view moves horizontally..
First time when user selects the category the delegate method will call.In this method also i am creating table view and labels as shown below only..
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
{
#try {
cancelScroll = NO;
if (scrollEnabled) {
scrollEnabled = NO;
NSLog(#"Begin Scroll Dragging");
NSLog(#"%f -- %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
if (scrollDirection == 1) {
scrollDirection = 0;
CGRect rect = mainTable.frame;
[scrollTableView scrollRectToVisible:rect animated:NO];
return;
}
else if (scrollDirection == 2) {
scrollDirection = 0;
HUDProgress.alpha=0;
CGFloat pageWidth = scrollTableView.frame.size.width;
int page;
if (pageControlBeingUsed) {
page = pageControl.currentPage;
// pageControlBeingUsed = NO;
}
else {
page= floor((scrollTableView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
}
NSLog(#"%d",page);
if (page == [questionTextArray count] - 1) {
if (maxValueReached) {
CGRect rect = mainTable.frame;
[scrollTableView scrollRectToVisible:rect animated:NO];
return;
}
}
photoAlbumView.alpha = 0;
photoView.alpha = 0;
FileAddView.alpha = 0;
settingsView.alpha = 0;
refreshView.alpha = 0;
photoAlbumViewPortrait.alpha = 0;
FileAddViewPortrait.alpha = 0;
settingsViewPortrait.alpha = 0;
refreshViewPortrait.alpha = 0;
checkValueForTableView = TRUE;
if (orientation == 1 ) {
if (!expandAction) {
scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 720.0, 596.0);
}
else {
scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 930.0, 596.0);
}
}
else {
if (!expandAction) {
scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 520.0, 680.0);
}
else {
scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 720.0, 680.0);
}
}
if (page >= 0) {
if (page > tempPage) {
int difference = page - tempPage;
NSLog(#"%d",difference);
NSLog(#"%f",tableXPosition);
tableXPosition = (tableXPosition + (difference * tableWidthPosition));
NSLog(#"%f",tableXPosition);
}
else if (page < tempPage){
int difference = tempPage - page;
NSLog(#"%d",difference);
tableXPosition = abs ((difference * tableWidthPosition) - tableXPosition);
NSLog(#"%f",tableXPosition);
}
else {
CGRect rect = mainTable.frame;
[scrollTableView scrollRectToVisible:rect animated:NO];
}
}
if([questionTextArray count] > 1)
{
pageControl.numberOfPages = [questionTextArray count];
[pageControl addTarget:self action:#selector(changePage) forControlEvents:UIControlEventValueChanged];
if(scrollTableView != nil)
{
if (mainTable != nil) {
[mainTable release];
mainTable = [[UITableView alloc] initWithFrame:CGRectMake(tableXPosition , 45.0, tableWidthPosition, 565.0) style:UITableViewStyleGrouped];
}
mainTable.delegate = self;
mainTable.dataSource = self;
mainTable.scrollEnabled = YES;
mainTable.backgroundColor = [UIColor clearColor];
[mainTable reloadData];
[scrollTableView addSubview:mainTable];
}
NSLog(#"%d %d",page,previousPage);
if (page >= 0) {
if (previousPage != page) {
pageControl.currentPage= page;
}
}
if (page >= 0) {
if (previousPage != page) {
UIImageView *imgView = [[UIImageView alloc] init];
UILabel *questionTextLbl1 = [[UILabel alloc] init];
UILabel *questionNumberLbl1 = [[UILabel alloc] init];
if (orientation == 1) {
if (!expandAction) {
imgView.frame = CGRectMake(tableXPosition, 0.0, 710.0, 39.0);
questionTextLbl1.frame = CGRectMake(10.0, 2.0, 430.0, 35.0);
questionNumberLbl1.frame = CGRectMake(550.0, 2.0, 200.0, 35.0);
}
else {
imgView.frame = CGRectMake(tableXPosition, 0.0, 920.0, 39.0);
questionTextLbl1.frame = CGRectMake(50.0, 2.0, 500.0, 35.0);
questionNumberLbl1.frame = CGRectMake(800.0, 2.0, 150.0, 35.0);
compressButton = [UIButton buttonWithType:UIButtonTypeCustom];
compressButton.frame = CGRectMake(10.0, 10.0, 25.0, 25.0);
[compressButton setImage:[UIImage imageNamed:#"Drop Down small2.png"] forState:UIControlStateNormal];
[compressButton addTarget:self action:#selector(compressAction) forControlEvents:UIControlEventTouchUpInside];
}
imgView.contentMode = UIViewContentModeScaleToFill;
imgView.backgroundColor = [UIColor clearColor];
imgView.image = [UIImage imageNamed:#"Top gary header.png"];
[scrollTableView addSubview:imgView];
if (!expandAction) {
}
else {
compressButton.backgroundColor = [UIColor clearColor];
[compressButton addTarget:self action:#selector(compressAction) forControlEvents:UIControlEventTouchUpInside];
[imgView addSubview:compressButton];
imgView.userInteractionEnabled = YES;
}
questionTextLbl1.backgroundColor = [UIColor clearColor];
questionTextLbl1.numberOfLines = 0;
questionTextLbl1.text = [NSString stringWithFormat:#"%d.%#?",page + 1,[questionTextArray objectAtIndex:page]];
NSLog(#"Question arry %#", questionTextArray);
[imgView addSubview:questionTextLbl1];
if([questionTextArray count] > 1)
{
questionNumberLbl1.text = [NSString stringWithFormat:#"Question %d/%d",page + 1,[questionTextArray count]];
}
else {
questionNumberLbl1.text = [NSString stringWithFormat:#"Question 1"];
}
questionNumberLbl1.backgroundColor = [UIColor clearColor];
questionNumberLbl1.numberOfLines = 0;
[imgView addSubview:questionNumberLbl1];
}
else {
if (!expandAction) {
imgView.frame = CGRectMake(tableXPosition, 0.0, 530.0, 38.0);
questionTextLbl1.frame = CGRectMake(10.0, 2.0, 350.0, 35.0);
questionNumberLbl1.frame = CGRectMake(380.0, 2.0, 150.0, 35.0);
}
else {
imgView.frame = CGRectMake(tableXPosition, 0.0, 720.0, 38.0);
questionTextLbl1.frame = CGRectMake(40.0, 2.0, 500.0, 35.0);
questionNumberLbl1.frame = CGRectMake(550.0, 2.0, 150.0, 35.0);
compressButton = [UIButton buttonWithType:UIButtonTypeCustom];
compressButton.frame = CGRectMake(10.0, 10.0, 25.0, 25.0);
[compressButton setImage:[UIImage imageNamed:#"Drop Down small2.png"] forState:UIControlStateNormal];
[compressButton addTarget:self action:#selector(compressAction) forControlEvents:UIControlEventTouchUpInside];
}
imgView.contentMode = UIViewContentModeScaleToFill;
imgView.backgroundColor = [UIColor clearColor];
imgView.image = [UIImage imageNamed:#"Top gary header.png"];
[scrollTableView addSubview:imgView];
if (!expandAction) {
}
else {
[imgView addSubview:compressButton];
imgView.userInteractionEnabled = YES;
}
questionTextLbl1.backgroundColor = [UIColor clearColor];
questionTextLbl1.numberOfLines = 0;
questionTextLbl1.font = [UIFont systemFontOfSize:14.0];
questionTextLbl1.text = [NSString stringWithFormat:#"%d.%#?",page + 1,[questionTextArray objectAtIndex:page]];
NSLog(#"Question arry %#", questionTextArray);
[imgView addSubview:questionTextLbl1];
if([questionTextArray count] > 1)
{
questionNumberLbl1.text = [NSString stringWithFormat:#"Question %d/%d",page + 1,[questionTextArray count]];
}
else {
questionNumberLbl1.text = [NSString stringWithFormat:#"Question 1"];
}
questionNumberLbl1.backgroundColor = [UIColor clearColor];
questionNumberLbl1.numberOfLines = 0;
[imgView addSubview:questionNumberLbl1];
}
[mainTable reloadData];
// [scrollTableView addSubview:mainTable];
[imgView release];
[questionNumberLbl1 release];
[questionTextLbl1 release];
//
CGRect rect = mainTable.frame;
if (pageControlBeingUsed) {
[scrollTableView scrollRectToVisible:rect animated:YES];
pageControlBeingUsed = NO;
}
else {
[scrollTableView scrollRectToVisible:rect animated:NO];
}
tempPage = page;
previousPage = page;
if (page == [questionTextArray count] - 1){
maxValueReached = YES;
}
else {
maxValueReached = NO;
}
}
}
NSLog(#"page:%d previous page:%d temp page:%d",page,previousPage,tempPage);
// sleep(0);
}
}
}
else {
[self killScroll];
scrollDirection = 0;
}
}
#catch (NSException *exception) {
NSLog(#"Exception: %#---%#",[exception name],[exception reason]);
}
#finally {
NSLog(#"Finally block");
}
}
It is working fine in simulator but in iPad for some time it is working fine while scrolling
after scrolling 15 or 20 times it is crashing..
Some times when running with instruments also crash log not showing anything and sometimes it is showing memory warning..
Related
I am updating one app to iOS 6 to iOS 7. But I am getting issue regarding kind of class. In iOS 6 it is showing class name custom button but in iOS 7 it displays _UITextContainerView.
for (UIView *subView in textViewButton.subviews)
{
NSLog(#"yourObject is a: %#", [subView class]);
#autoreleasepool
{
if([subView isKindOfClass:[CustomButton class]])
{
CustomButton *button = (CustomButton*)subView;
button.backgroundColor = [UIColor redColor];
[button setType:kButtonTypeQuestion];
button.titleLabel.font = kFontForContentPhone;
if (button.tag == 62254 || button.tag == 62263)
{
CGRect tempFrame = button.frame;
tempFrame.origin.x = button.frame.origin.x - 3.0f;
button.frame = tempFrame;
}
if (self.soundFile != nil)
{
CGRect tempFrame = button.frame;
tempFrame.size.width = button.frame.size.width + 28.0f;
button.frame = tempFrame;
[button setContentEdgeInsets:UIEdgeInsetsMake(5.0f, 30.0f, 5.0f, 10.0f)];
}
}
}
}
Update
pragma mark - Text Paragraph iPhone
self.questionScrollView = [[CustomScrollView alloc] initWithFrame:CGRectMake(0, currentYPosition, self.frame.size.width, self.frame.size.height - currentYPosition - 60.0f)];
self.questionScrollView.showsVerticalScrollIndicator = NO;
self.questionsContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.questionScrollView.frame.size.width, self.questionScrollView.frame.size.height)];
currentYPosition = 0;
for (Question *question in self.questions)
{
#autoreleasepool
{
self.ttmItem = [[TapToMoveItem alloc] initWithFrame:CGRectMake(0, currentYPosition, self.frame.size.width, self.frame.size.height)];
self.ttmItem.ttmDelegate = self;
self.ttmItem.variant = self.exercise.variant;
ttmItem.x_Position = question.x_position;
ttmItem.y_Position = question.y_position;
if ([question.sound_file length] > 0 || question.sound_file != nil)
self.ttmItem.hasAudio = YES;
else
self.ttmItem.hasAudio = NO;
if ([kPrefixImage isEqualToString:#"preint_"] && ([self.exercise.exercise_id integerValue] == 54 || [self.exercise.exercise_id integerValue] == 91)) {
ttmItem.soundFile = self.exercise.header_title;
}
self.ttmItem.prefix = question.prefix;
self.ttmItem.text = question.text;
self.ttmItem.longestPrefix = longestPrefix;
self.ttmItem.longestAnswer = longestAnswer;
self.ttmItem.buttonWidth = sizeForButton.width;
//get and set answers
ttmItem.answers = [self.answers objectForKey:question.question_id];
[self.ttmItem createForPhone];
[self.questionsContainer addSubview:self.ttmItem];
currentYPosition += ttmItem.frame.size.height + SPACE_BET_VIEWS;
// itemHeight = ttmItem.frame.size.height; //hack
// itemWidth = ttmItem.frame.size.width;
ttmCount++;
if ([ttmItem.arrayOfTextViewButtons count] > 0) {
[dictionaryOfItemButtons setObject:ttmItem.arrayOfTextViewButtons forKey:question.question_id];
}
}
}
self.questionsContainer.frame = CGRectMake(questionsContainer.frame.origin.x, questionsContainer.frame.origin.y, questionsContainer.frame.size.width, currentYPosition );
[self.questionScrollView setContentSize:self.questionsContainer.frame.size];
[self.questionScrollView addSubview:self.questionsContainer];
[self addSubview:self.questionScrollView];
[self setScrollEnabled:NO];
}
I am unable to find that why it is showing different in class name of any object. Moreover I didn't find any issue regarding this on google. Please help me if someone has an idea about this.
Thanks in advance.
I have resolved this issue by doing this :
for (UIView *subView in textViewButton.textInputView.subviews)
{
// const char* className = class_getName([yourObject class]);
NSLog(#"yourObject is a: %#", [subView class]);
#autoreleasepool
{
if([subView isKindOfClass:[CustomButton class]])
{
CustomButton *button = (CustomButton*)subView;
button.backgroundColor = [UIColor clearColor];
[button setType:kButtonTypeQuestion];
button.titleLabel.font = kFontForContentPhone;
if (button.tag == 62254 || button.tag == 62263)
{
CGRect tempFrame = button.frame;
tempFrame.origin.x = button.frame.origin.x - 3.0f;
button.frame = tempFrame;
}
if (self.soundFile != nil)
{
CGRect tempFrame = button.frame;
tempFrame.size.width = button.frame.size.width + 28.0f;
button.frame = tempFrame;
[button setContentEdgeInsets:UIEdgeInsetsMake(5.0f, 30.0f, 5.0f, 10.0f)];
}
}
}
}
Loop through all the subviews as well until you found your object. if you happen to find the object exit the loop to save any unnecessary resources
for (UIView *subView in textViewButton.subviews)
{
NSLog(#"yourObject is a: %#", [subView class]);
#autoreleasepool
{
if([subView isKindOfClass:[CustomButton class]])
{
CustomButton *button = (CustomButton*)subView;
button.backgroundColor = [UIColor redColor];
[button setType:kButtonTypeQuestion];
button.titleLabel.font = kFontForContentPhone;
if (button.tag == 62254 || button.tag == 62263)
{
CGRect tempFrame = button.frame;
tempFrame.origin.x = button.frame.origin.x - 3.0f;
button.frame = tempFrame;
}
if (self.soundFile != nil)
{
CGRect tempFrame = button.frame;
tempFrame.size.width = button.frame.size.width + 28.0f;
button.frame = tempFrame;
[button setContentEdgeInsets:UIEdgeInsetsMake(5.0f, 30.0f, 5.0f, 10.0f)];
}
}
else if ([subView isKindOfClass:NSClassFromString(#"_UITextContainerView")]) {
// do a another loop
for (UIView *innerSubViews in subView.subviews) {
if([subView isKindOfClass:[CustomButton class]])
{
// call your custom button method here
break; // stop inner loop
}
}
}
}
}
The UIScrollView (upon calling from a button click action) will only scroll a few pixels short of the bottom of the content size window. This problem only occurs when called from a certain function.
- (void)adjustScrollView {
SVscrollableLayout.contentSize = CGSizeMake(SVscrollableLayout.frame.size.width, CGRectGetMaxY(bottomSubview.frame));
}
Problematic Function:
- (IBAction)BTNdeleteAction:(id)sender {
[self clearSubviews];
//Do some stuff to remove the deleted subview
[self displaySubviews];
[self adjustScrollView];
}
- (void)temporarilyClearClasses {
int numberOfClasses = [self loadNumberOfClasses];
for (int i=0; i<numberOfClasses; i++) {
UIButton* TXTclassDisplayTemp = (UIButton*)[self.view viewWithTag:100+i];
[TXTclassDisplayTemp removeFromSuperview];
UIButton* BTNdeleteButtonTemp = (UIButton*)[self.view viewWithTag:200+i];
[BTNdeleteButtonTemp removeFromSuperview];
}
}
- (void)printClasses {
int numberOfClasses = [self loadNumberOfClasses];
NSArray* classNames = [NSArray arrayWithArray:[self loadClassesArray]];
int yPlacement = 0;
if (numberOfClasses != 0) {
if (noClasses == YES)
for (int i=0; i<numberOfClasses; i++) {
UIButton* TXTnewClass = [[UIButton alloc] initWithFrame:CGRectMake(0, 10+(50*i), self.view.frame.size.width, 35)];
TXTnewClass.tag = 100+i;
[TXTnewClass addTarget:self
action:#selector(TXTclassDisplayAction:)
forControlEvents:UIControlEventTouchUpInside];
deleteAllButtonYplacement = CGRectGetMaxY(TXTnewClass.frame)+10 ;
UIButton* BTNdeleteClass = [UIButton buttonWithType:UIButtonTypeCustom];
BTNdeleteClass.frame = CGRectMake(10, yPlacement+10+(50*i), 70, 35);
BTNdeleteClass.tag = 200+i;
[BTNdeleteClass setTitle:#"Delete" forState:UIControlStateNormal];
if ([self editingStatus] == OFF)
BTNdeleteClass.hidden = YES;
[SVscrollableLayout addSubview:BTNdeleteClass];
if (CGRectGetMaxY(TXTnewClass.frame) <= SVscrollableLayout.frame.size.height) {
SVscrollableLayout.contentSize = SVscrollableLayout.frame.size;
}
else {
while (CGRectGetMaxY(TXTnewClass.frame) > SVscrollableLayout.contentSize.height) {
SVscrollableLayout.contentSize = CGSizeMake(SVscrollableLayout.frame.size.width, SVscrollableLayout.contentSize.height + 5);
}
}
}
}
else {
TXTnoClasses.hidden = NO;
BTNeditClassList.enabled = NO;
BTNeditClassList.alpha = 0.4;
}
float centerHorizontal = self.view.frame.size.width / 2;
float deleteAllButtonXplacement = centerHorizontal - (93/2) - 3;
NSLog(#"%f", BTNdeleteAll.frame.size.width);
[self refreshDeleteButton:CGRectMake(deleteAllButtonXplacement, deleteAllButtonYplacement, 93, 44)];
[self adjustScrollView];
}
In one of the projects I'm working on, I have a UIScrollView that has a lot of buttons and labels that resemble movie theater seats that the user can tap to select seats for them to buy. Is it possible to zoom the UIScrollView? I have already declared the UIScrollViewDelegate, set the delegate to self, set the minimum and maximum zoom scale but I'm having issues with the viewForZoomingInScrollView and scrollViewDidEndZooming methods. I tried to return my scrollview on the viewForZoomingInScrollView method but it crashes.
Here's some of the code:
- (void) renderSeatMapOnScreen
{
int x_offset_row = 10;
int y_offset_row = 25;
int x_offset_col = 30;
int y_offset_col = 0;
int scrollview_w = 0;
int scrollview_h = 0;
NSString *row_name = #"";
int tag_index = 0;
NSMutableArray *seat_map_table = [seat_map_xml seats_map];
NSString *seat_available_str = [seat_avail_xml seat_available];
HideNetworkActivityIndicator();
NSLog(#"Seats available = %#", seat_available_str);
NSArray *seats_avail = [seat_available_str componentsSeparatedByString:#";"];
int ROW_COL_OFFSET = 25;
for (int row = 0; row < [seat_map_table count]; row++)
{
UILabel * rowlabel = [[UILabel alloc] init];
rowlabel.frame = CGRectMake(x_offset_row , y_offset_row, 22, 22);
SeatMapDeclaration *rowmap = [seat_map_table objectAtIndex:row];
rowlabel.text = rowmap.rows;
[scrollview addSubview:rowlabel];
row_name = [NSString stringWithFormat:#"%#", rowmap.rows];
NSArray *seat = [rowmap.rowmap componentsSeparatedByString:#";"];
NSLog(#"row[%i] = %#", row, rowmap.rowmap);
if (row == 0)
{
scrollview_w = [seat count] * ROW_COL_OFFSET + y_offset_row;
total_column = [seat count];
total_row = [seat_map_table count];
}
x_offset_col = 30 ;
y_offset_col = y_offset_row ;
for (int column = 0; column < [seat count]; column++)
{
if (([[seat objectAtIndex:column] rangeOfString:#"a("].location != NSNotFound)
|| ([[seat objectAtIndex:column] isEqualToString:#""]))
{
CGRect myImageRect = CGRectMake(x_offset_col, y_offset_col, 22, 22);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImageRect];
[imageView setImage:[UIImage imageNamed:#"noseat.png"]];
[scrollview addSubview:imageView];
}
else if ([[seat objectAtIndex:column] rangeOfString:#"b("].location != NSNotFound)
{
CGRect myImageRect = CGRectMake(x_offset_col, y_offset_col, 22, 22);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImageRect];
imageView.image = [UIImage imageNamed:#"noseat.png"];
[scrollview addSubview:imageView];
}
else
{
NSString *status = [NSString stringWithFormat:#"%#%#", row_name, [seat objectAtIndex:column]];
BOOL matchedFound = NO;
for (int i = 0; i < [seats_avail count]; i++)
{
if ([[seats_avail objectAtIndex:i] isEqualToString:status])
{
matchedFound = YES ;
break ;
}
}
if (matchedFound == YES)
{
UIButton * seat_btn = [UIButton buttonWithType:UIButtonTypeCustom];
[seat_btn setBackgroundImage:[UIImage imageNamed:#"seatavailable.png"] forState:UIControlStateNormal];
[seat_btn setBackgroundImage:[UIImage imageNamed:#"seatactive.png"] forState:UIControlStateSelected];
seat_btn.frame = CGRectMake(x_offset_col, y_offset_col, 22, 22);
tag_index = [[seat objectAtIndex:column] intValue];
[seat_btn setTitle:[seat objectAtIndex:column] forState:UIControlStateNormal];
seat_btn.titleLabel.font = [UIFont fontWithName:#"Helvetica" size:12.0];
seat_btn.tag = tag_index + row * 100;
[seat_btn addTarget:self
action:#selector(checkboxButton:)
forControlEvents:UIControlEventTouchUpInside];
[scrollview addSubview:seat_btn];
}
else
{
CGRect myImageRect = CGRectMake(x_offset_col, y_offset_col, 22, 22);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImageRect];
imageView.image = [UIImage imageNamed:#"seat_not_available.png"];
[scrollview addSubview:imageView];
}
}
x_offset_col += ROW_COL_OFFSET ;
NSString *data = #"";
[seatControl addObject:data];
}
y_offset_row += ROW_COL_OFFSET;
}
UILabel *screenlabel = [[UILabel alloc] init];
screenlabel.frame = CGRectMake((scrollview_w-300)/2, 3, 300, 15);
screenlabel.text = #"Screen";
screenlabel.backgroundColor = [UIColor blackColor];
screenlabel.textColor = [UIColor whiteColor] ;
screenlabel.font = [UIFont fontWithName:#"Helvetica" size:10.0];
screenlabel.textAlignment = UITextAlignmentCenter;
[scrollview addSubview:screenlabel];
scrollview_h = y_offset_row + ROW_COL_OFFSET;
// Adjust scroll view
[scrollview setContentSize:CGSizeMake(scrollview_w, scrollview_h )];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
NSLog(#"1");
return scrollview;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
NSLog(#"2");
}
In:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
NSLog(#"1");
return scrollview;
}
you are not supposed to return the UIScrollView itself, rather its subview that you would like to scroll/zoom.
If you have many subviews, I would suggest creating a container view for all of them that you return from viewForZoomingInScrollView; instead of adding your seats to the scrollview itself you would then add them to the container view.
If you want to zoom to a certain seat in the UIScrollView, you should use zoomToRect: animated:. You can specify a certain rectangle (i.e. the seat) to which you would like to zoom in on.
Zooming only works when you implement the viewForZoomingInScrollView: delegate callback.
UIImageView *tempImage = [[UIImageView alloc]initWithImage:[UIImage imageWithData:data]];
self.imageView = tempImage;
scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
scrollView.maximumZoomScale = 1;
scrollView.minimumZoomScale = .37;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
scrollView.zoomScale = .37;
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
return imageView;
}
My scenario is when scrollview moving horizontally it has to show one question with table view and with some controls inside table view..
When moving scrollview horizontally i am releasing previous tables and labels and creating new tables and new labels.
But my app is crashing after scrolling some 20 times i.e., in device only but working fine in simulator.
I run app with instruments there are no leaks..
My doubt is that is there any problem with this iPAD 1st generation RAM means not sufficient or any other problem..
Here is my code..
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
#try {
cancelScroll = NO;
if (scrollEnabled) {
scrollEnabled = NO;
NSLog(#"Begin Scroll Dragging");
NSLog(#"%f -- %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
if (scrollDirection == 1) {
scrollDirection = 0;
rect = mainTable.frame;
[scrollTableView scrollRectToVisible:rect animated:NO];
return;
}
else if (scrollDirection == 2) {
scrollDirection = 0;
HUDProgress.alpha=0;
pageWidth = scrollTableView.frame.size.width;
if (pageControlBeingUsed) {
page = pageControl.currentPage;
}
else {
page= floor((scrollTableView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
}
NSLog(#"%d",page);
if (page == [questionTextArray count] - 1) {
if (maxValueReached) {
rect = mainTable.frame;
[scrollTableView scrollRectToVisible:rect animated:NO];
return;
}
}
photoAlbumView.alpha = 0;
photoView.alpha = 0;
FileAddView.alpha = 0;
settingsView.alpha = 0;
refreshView.alpha = 0;
photoAlbumViewPortrait.alpha = 0;
FileAddViewPortrait.alpha = 0;
settingsViewPortrait.alpha = 0;
refreshViewPortrait.alpha = 0;
checkValueForTableView = TRUE;
if (orientation == 1 ) {
if (!expandAction) {
scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 720.0, 596.0);
}
else {
scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 930.0, 596.0);
}
}
else {
if (!expandAction) {
scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 520.0, 680.0);
}
else {
scrollTableView.contentSize = CGSizeMake([questionTextArray count] * 720.0, 680.0);
}
}
if (page >= 0) {
if (page > tempPage) {
difference = page - tempPage;
NSLog(#"%d",difference);
NSLog(#"%f",tableXPosition);
tableXPosition = (tableXPosition + (difference * tableWidthPosition));
NSLog(#"%f",tableXPosition);
}
else if (page < tempPage){
difference = tempPage - page;
NSLog(#"%d",difference);
tableXPosition = abs ((difference * tableWidthPosition) - tableXPosition);
NSLog(#"%f",tableXPosition);
}
else {
rect = mainTable.frame;
[scrollTableView scrollRectToVisible:rect animated:NO];
}
}
if([questionTextArray count] > 1)
{
pageControl.numberOfPages = [questionTextArray count];
[pageControl addTarget:self action:#selector(changePage) forControlEvents:UIControlEventValueChanged];
if(scrollTableView != nil)
{
if (mainTable != nil) {
// mainTable.delegate = nil;
[mainTable release];
mainTable = [[UITableView alloc] initWithFrame:CGRectMake(tableXPosition , 45.0, tableWidthPosition, 565.0) style:UITableViewStyleGrouped];
}
mainTable.delegate = self;
mainTable.dataSource = self;
mainTable.scrollEnabled = YES;
mainTable.backgroundColor = [UIColor clearColor];
[mainTable reloadData];
[scrollTableView addSubview:mainTable];
}
NSLog(#"%d %d",page,previousPage);
if (page >= 0) {
if (previousPage != page) {
pageControl.currentPage= page;
}
}
if (page >= 0) {
if (previousPage != page) {
UIImageView *imgView = [[UIImageView alloc] init];
UILabel *questionTextLbl1 = [[UILabel alloc] init];
UILabel *questionNumberLbl1 = [[UILabel alloc] init];
if (orientation == 1) {
if (!expandAction) {
imgView.frame = CGRectMake(tableXPosition, 0.0, 710.0, 39.0);
questionTextLbl1.frame = CGRectMake(10.0, 2.0, 430.0, 35.0);
questionNumberLbl1.frame = CGRectMake(550.0, 2.0, 200.0, 35.0);
}
else {
imgView.frame = CGRectMake(tableXPosition, 0.0, 920.0, 39.0);
questionTextLbl1.frame = CGRectMake(50.0, 2.0, 500.0, 35.0);
questionNumberLbl1.frame = CGRectMake(800.0, 2.0, 150.0, 35.0);
compressButton = [UIButton buttonWithType:UIButtonTypeCustom];
compressButton.frame = CGRectMake(10.0, 10.0, 25.0, 25.0);
[compressButton setImage:[UIImage imageNamed:#"Drop Down small2.png"] forState:UIControlStateNormal];
[compressButton addTarget:self action:#selector(compressAction) forControlEvents:UIControlEventTouchUpInside];
}
imgView.contentMode = UIViewContentModeScaleToFill;
imgView.backgroundColor = [UIColor clearColor];
imgView.image = [UIImage imageNamed:#"Top gary header.png"];
[scrollTableView addSubview:imgView];
if (!expandAction) {
NSLog(#"expandAction");
}
else {
compressButton.backgroundColor = [UIColor clearColor];
[compressButton addTarget:self action:#selector(compressAction) forControlEvents:UIControlEventTouchUpInside];
[imgView addSubview:compressButton];
imgView.userInteractionEnabled = YES;
}
questionTextLbl1.backgroundColor = [UIColor clearColor];
questionTextLbl1.numberOfLines = 0;
questionTextLbl1.text = [NSString stringWithFormat:#"%d.%#?",page + 1,[questionTextArray objectAtIndex:page]];
NSLog(#"Question arry %#", questionTextArray);
[imgView addSubview:questionTextLbl1];
if([questionTextArray count] > 1)
{
questionNumberLbl1.text = [NSString stringWithFormat:#"Question %d/%d",page + 1,[questionTextArray count]];
}
else {
questionNumberLbl1.text = [NSString stringWithFormat:#"Question 1"];
}
questionNumberLbl1.backgroundColor = [UIColor clearColor];
questionNumberLbl1.numberOfLines = 0;
[imgView addSubview:questionNumberLbl1];
}
else {
if (!expandAction) {
imgView.frame = CGRectMake(tableXPosition, 0.0, 530.0, 38.0);
questionTextLbl1.frame = CGRectMake(10.0, 2.0, 350.0, 35.0);
questionNumberLbl1.frame = CGRectMake(380.0, 2.0, 150.0, 35.0);
}
else {
imgView.frame = CGRectMake(tableXPosition, 0.0, 720.0, 38.0);
questionTextLbl1.frame = CGRectMake(40.0, 2.0, 500.0, 35.0);
questionNumberLbl1.frame = CGRectMake(550.0, 2.0, 150.0, 35.0);
compressButton = [UIButton buttonWithType:UIButtonTypeCustom];
compressButton.frame = CGRectMake(10.0, 10.0, 25.0, 25.0);
[compressButton setImage:[UIImage imageNamed:#"Drop Down small2.png"] forState:UIControlStateNormal];
[compressButton addTarget:self action:#selector(compressAction) forControlEvents:UIControlEventTouchUpInside];
}
imgView.contentMode = UIViewContentModeScaleToFill;
imgView.backgroundColor = [UIColor clearColor];
imgView.image = [UIImage imageNamed:#"Top gary header.png"];
[scrollTableView addSubview:imgView];
if (!expandAction) {
NSLog(#"expandAction");
}
else {
[imgView addSubview:compressButton];
imgView.userInteractionEnabled = YES;
}
questionTextLbl1.backgroundColor = [UIColor clearColor];
questionTextLbl1.numberOfLines = 0;
questionTextLbl1.font = [UIFont systemFontOfSize:14.0];
questionTextLbl1.text = [NSString stringWithFormat:#"%d.%#?",page + 1,[questionTextArray objectAtIndex:page]];
NSLog(#"Question arry %#", questionTextArray);
[imgView addSubview:questionTextLbl1];
if([questionTextArray count] > 1)
{
questionNumberLbl1.text = [NSString stringWithFormat:#"Question %d/%d",page + 1,[questionTextArray count]];
}
else {
questionNumberLbl1.text = [NSString stringWithFormat:#"Question 1"];
}
questionNumberLbl1.backgroundColor = [UIColor clearColor];
questionNumberLbl1.numberOfLines = 0;
[imgView addSubview:questionNumberLbl1];
}
[mainTable reloadData];
// [scrollTableView addSubview:mainTable];
rect = mainTable.frame;
if (pageControlBeingUsed) {
[scrollTableView scrollRectToVisible:rect animated:YES];
pageControlBeingUsed = NO;
}
else {
[scrollTableView scrollRectToVisible:rect animated:NO];
}
tempPage = page;
previousPage = page;
if (page == [questionTextArray count] - 1){
maxValueReached = YES;
}
else {
maxValueReached = NO;
}
[imgView release];
[questionNumberLbl1 release];
[questionTextLbl1 release];
}
}
NSLog(#"page:%d previous page:%d temp page:%d",page,previousPage,tempPage);
}
}
}
else {
[self killScroll];
scrollDirection = 0;
}
}
#catch (NSException *exception) {
NSLog(#"Exception: %#---%#",[exception name],[exception reason]);
}
#finally {
NSLog(#"Finally block");
}
}
My doubt is that is there any problem with this iPAD 1st generation RAM means not sufficient or any other problem.
Your intuition about memory is correct, IMO. Your method is really hard to follow, so I am not sure but it seems that you are instantiating a log of views and label and adding them to your main scrollTableView, but never removing them. That could explain the memory fill-up.
Take imgView, you instantiate it:
UIImageView *imgView = [[UIImageView alloc] init];
add it to scrollTableView:
[scrollTableView addSubview:imgView];
add several subviews to imgView:
[imgView addSubview:questionTextLbl1];
[imgView addSubview:questionNumberLbl1];
you release it correctly:
[imgView release];
but I cannot see any place where you remove imgView from scrollTableView before adding a new imgView to it... so you just keep adding imgView on top of imgView...
A simple way to check whether what I am saying is true is adding this statement to scrollViewDidEndDecelerating:
NSLog(#"LOGGING NUMBER OF SUBVIEWS: %d", [scrollTableView.subviews count]);
e.g.,
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
#try {
cancelScroll = NO;
if (scrollEnabled) {
NSLog(#"LOGGING NUMBER OF SUBVIEWS: %d", [scrollTableView.subviews count]);
...
and you will se that each time that you scroll, the number of subviews will increase.
Can any one tell me why I am getting this error ?
[myClassName
tableView:numberOfRowsInSection:]:
unrecognized selector sent to instance
0x8ad5a90'
I know what does it means but in myClassName class I didn't use any uitableview!!!! I have a scrollview in this class not tableView so I could not find why I am getting this error.
EDITED :
- (void)viewDidLoad
{
imageIndex = 0;
int count =0;
int totalScrollRow = 0;
myScroll.contentSize = CGSizeMake(0, 397);
NSLog(#"%f",myScroll.contentSize.height);
volPhotoApp = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
volPhotoApp.photoGalleryIndex = 0 ;
eventRow = [volPhotoApp.volPhotoArray objectAtIndex:selectedIndex];
numberOfImages = [eventRow.photoArray count];
if (numberOfImages == 0)
{
UILabel *zeroLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 200)];
zeroLabel.text = #"No Images..";
[myScroll addSubview:zeroLabel];
return;
}
header.enabled =NO;
[header setTitle:eventRow.title forState:UIControlStateNormal];
CGRect contentRect = myScroll.bounds;
CGFloat boundX = contentRect.origin.x;
CGFloat boundY = contentRect.origin.y;
CGRect frame1 ;
for (int i=0, X=5 ; i < numberOfImages; i++, X+=80)
{
if (count == 4)
{
boundX = 5;
boundY += 70;
X = 0;
count = 0;
}
frame1 = CGRectMake(boundX+X ,boundY+5, 70, 65);
AsyncImageView *av1 = [[AsyncImageView alloc] initWithFrame:frame1];
[av1 loadImageFromURL:[NSURL URLWithString:[eventRow.photoArray objectAtIndex:volPhotoApp.photoGalleryIndex]]];
av1.backgroundColor = [UIColor clearColor];
volPhotoApp.photoGalleryIndex++;
UIButton *b1 = [[UIButton alloc] initWithFrame:frame1];
b1.backgroundColor = [UIColor clearColor];
[b1 setTitle:#"" forState:UIControlStateNormal];
b1.tag = volPhotoApp.photoGalleryIndex;
[b1 addTarget:self action:#selector(aMethod:) forControlEvents:UIControlEventTouchDown];
b1.enabled = YES;
count++;
[myScroll addSubview:av1];
[myScroll addSubview:b1];
totalScrollRow++;
if (volPhotoApp.photoGalleryIndex == numberOfImages)
{
volPhotoApp.photoGalleryIndex = 0 ;
break;
}
}
NSLog(#"%f",boundY);
NSLog(#"%d",totalScrollRow);
NSLog(#"%f",myScroll.contentSize.height);
if (boundY > myScroll.contentSize.height || totalScrollRow > 20)
{
myScroll.contentSize = CGSizeMake(0, boundY+75);
}
[super viewDidLoad];
}
Thanks..
Could you be inheriting from UITableViewController or acting as the delegate? Without code it's only guessing.