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.
Related
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.
I am trying to add a subview on ImageView control, I think, i have alloc view and dealloc view properly.This is my code.
for(int Count =0; Count < [list count]; Count++)
{
MapCallout *callout = [list objectAtIndex:Count];
CGSize constSize = { 700.0f, 40.0f };
NSString * sTmp = [callout.Name stringByAppendingString:#"WW"];
CGSize textSize = [sTmp sizeWithFont:[UIFont fontWithName:#"Arial-BoldMT" size:25.0] constrainedToSize:constSize lineBreakMode:UILineBreakModeClip];
int xValue = callout.X;
int yValue = callout.Y;
int position = 0;
UIImage *calloutImage;
if(callout.Direction==0)
{
calloutImage=[UIImage newImageFromResource:#"arrow-0.png"];
callout.Y=callout.Y-3; position= -3;
}
else if(callout.Direction==1)
{
calloutImage=[UIImage newImageFromResource:#"arrow-1.png"];
callout.Y=callout.Y-3; position= -3;
}
else if(callout.Direction==2)
{
callout.Y=callout.Y + 2;
calloutImage=[UIImage newImageFromResource:#"arrow_2.png"];
position= +2;
}
CalloutButton *calloutButton = nil;
int arraySize = [dequeueReusableCallout count] - 1;
if(Count > arraySize)
{
calloutButton = [[[CalloutButton alloc]initWithFrame:CGRectMake(xValue,
self.tapDetectingImageView.frame.origin.y + yValue ,
textSize.width,40)] autorelease];
[calloutButton setDelegate:self];
[dequeueReusableCallout addObject:calloutButton];
}
calloutButton = [dequeueReusableCallout objectAtIndex:Count];
[calloutButton setFrame:CGRectMake(xValue,
self.tapDetectingImageView.frame.origin.y + yValue ,
textSize.width,40)] ;
[calloutButton setBackgroundImage:calloutImage andText:callout.Name andYvalue:position];
calloutButton.tag = callout.ID;
calloutButton.ViewMapType = [callout.calloutType intValue];
calloutButton.isLive = callout.isLive;
calloutButton.isAnimated = callout.isAnimated;
[self.tapDetectingImageView addSubview:calloutButton];
}
//Callout Button Method
-(void) setBackgroundImage:(UIImage*)image andText:(NSString*)text andYvalue:(double)Y
{
if(!btnCallout)
btnCallout = [[UIButton alloc] init];
[btnCallout setFrame:CGRectMake(0, -Y, self.frame.size.width, self.frame.size.height)];
[btnCallout setBackgroundImage:image forState:UIControlStateNormal];
[btnCallout addTarget:self action:#selector(CalloutTouch:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btnCallout];
if(!lblCallout)
lblCallout = [[UILabel alloc] init];
[lblCallout setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
lblCallout.backgroundColor = [UIColor clearColor];
lblCallout.font = [UIFont systemFontOfSize:42.0];
lblCallout.userInteractionEnabled = NO;
lblCallout.text = text;
lblCallout.textAlignment = UITextAlignmentCenter;
lblCallout.font = [UIFont fontWithName:#"Arial-BoldMT" size:25.0];
[self addSubview:lblCallout];
}
[self viewForZoomingInScrollView:self.mapScrollView];
}
If i call this method method multi-times, memory warning is occur and app get crash.
Here, [self.tapDetectingImageView addSubview:calloutButton]; I if comment this statement, it is working properly. Please let me know where i am wrong.
You should call [calloutButton release] after you add it to the dequeueReusableCallout array since the array now has a retain on the newly allocated instance
I am enclosing my sample code herewith for ready reference, please make it in center place, this is what I am facing problem in. It is not stopping on the center indicator.
Note : All button are dynamic and coming from web, but in this sample I made it from a hard coded array. But in original scenerio their count(number of buttons) may change.
- (void)viewDidLoad {
arr = [[NSMutableArray alloc] initWithObjects:#"Test1",#"Test2",#"Test3",#"Test4",#"Test5",nil];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bg_content_slide.png"]];
img.frame = CGRectMake(0, 20, 320, 85);
img.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:img];
[self setScrollButtons];
[super viewDidLoad];
}
- (void) setScrollButtons
{
UIScrollView *tagScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, 320, 44)];
tagScrollView.backgroundColor = [UIColor clearColor];
[tagScrollView setShowsHorizontalScrollIndicator:NO];
[tagScrollView setShowsVerticalScrollIndicator:NO];
[tagScrollView setCanCancelContentTouches:NO];
tagScrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
tagScrollView.clipsToBounds = YES;
tagScrollView.scrollEnabled = YES;
tagScrollView.pagingEnabled = YES;
tagScrollView.bounces = YES;
tagScrollView.tag = 2;
int xaxis = 0;
for (int i = 0; i < [arr count]; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(xaxis, 0, 160, 44);
//btn.titleLabel.text = [NSString stringWithFormat:#"%#",[arr objectAtIndex:i]];
[btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
NSLog(#"%#", btn.titleLabel.text);
xaxis += btn.frame.size.width + 20;
[tagScrollView addSubview:btn];
}
[tagScrollView setContentSize:CGSizeMake([arr count] * 200, tagScrollView.frame.size.height)];
[self.view addSubview:tagScrollView];
}
Find code here UnAligned scrollview code
chage ur code with this one
int xaxis = 0;
for (int i = 0; i < [arr count]; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(320*xaxis+80, 0, 160, 44);
//btn.titleLabel.text = [NSString stringWithFormat:#"%#",[arr objectAtIndex:i]];
[btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
//[btn setBackgroundImage:[UIImage imageNamed:#"remove_fav.png"] forState:UIControlStateNormal];
NSLog(#"%#", btn.titleLabel.text);
xaxis ++;//= btn.frame.size.width + 40;
[tagScrollView addSubview:btn];
}
[tagScrollView setContentSize:CGSizeMake([arr count] * 320, tagScrollView.frame.size.height)];
[self.view addSubview:tagScrollView];
it will solve ur problem
What you want to achieve is not possible when pagination is enabled as when pagination is enabled the scroll view scroll to its width.So for this what you can do max is add this method
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGPoint offset = scrollView.contentOffset;
int temp = floor(offset.x/160);
[tagScrollView scrollRectToVisible:CGRectMake(temp*160, 0, 320, 44) animated:YES];
}
its working fine for this configuration .......
{
int xaxis = 0;
for (int i = 0; i < [arr count]; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(160*xaxis+85, 0, 150, 44);
[btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
NSLog(#"%#", btn.titleLabel.text);
xaxis ++;//= btn.frame.size.width + 40;
[tagScrollView addSubview:btn];
}
[tagScrollView setContentSize:CGSizeMake(160*xaxis+250, tagScrollView.frame.size.height)];
}
and .....
tagScrollView.pagingEnabled = NO;