Issue in if/else block objective-c iPhone [closed] - iphone

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using the below code for assigning values to my labels and imageviews but its not working properly. I am not getting the issue
if ([child11 length] != 0) {
[childButton1 setAlpha:1];
[childButton2 setAlpha:0];
[childButton3 setAlpha:0];
[childButton4 setAlpha:0];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
//label1.text = child11;
NSLog(#"here we are");
if ([child11image isEqualToString:#"Fajar"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
NSLog(#"child11image::: %#", child11image);
label1.text = child11;
} else if ([child11image isEqualToString:#"Zuhr"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
label1.text = child11;
} else if ([child11image isEqualToString:#"Asr"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Large"]];
label1.text = child11;
NSLog(#"child11image::: %#", child11image);
} else if ([child11image isEqualToString:#"Maghrib"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
label1.text = child11;
} else if ([child11image isEqualToString:#"Isha"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
label1.text = child11;
}
} else if ([child22 length] != 0){
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:0];
[childButton4 setAlpha:0];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
label2.text = child22;
if ([child22image isEqualToString:#"Fajar"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Zuhr"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Asr"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Maghrib"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Isha"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child33 length] != 0){
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:1];
[childButton4 setAlpha:0];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
label3.text = child33;
if ([child33image isEqualToString:#"Fajar"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Zuhr"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Asr"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Maghrib"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Isha"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child44 length] != 0) {
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:1];
[childButton4 setAlpha:1];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
label4.text = child44;
if ([child44image isEqualToString:#"Fajar"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Zuhr"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Asr"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Maghrib"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Isha"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child55 length] != 0) {
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:1];
[childButton4 setAlpha:1];
[childButton5 setAlpha:1];
[childButton6 setAlpha:0];
label5.text = child55;
if ([child55image isEqualToString:#"Fajar"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Zuhr"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Asr"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Maghrib"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Isha"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child66 length] != 0) {
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:1];
[childButton4 setAlpha:1];
[childButton5 setAlpha:1];
[childButton6 setAlpha:1];
label6.text = child66;
if ([child66image isEqualToString:#"Fajar"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Zuhr"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Asr"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Maghrib"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Isha"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else ([child11 length] == 0) {
[childButton1 setAlpha:0];
[childButton2 setAlpha:0];
[childButton3 setAlpha:0];
[childButton4 setAlpha:0];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
}

You don't say what the actual problem is but the if statement has to be wrong. The first two conditions are
if ([child11 length] == 0)
{
// do stuff
}
else if ([child11 length] != 0)
{
// do stuff
}
else // nothing else matters
You will always go through one of the first two cases because (x == 0 || x != 0) == true by definition. All of the stuff to do with child22, child33 etc never gets done.

i think this is what you mean
if ([child11 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:0]; [childButton3 setAlpha:0]; [childButton4 setAlpha:0];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
label1.text = child11;
if ([child11image isEqualToString:#"Fajar"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child11image isEqualToString:#"Zuhr"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child11image isEqualToString:#"Asr"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Large"]];
} else if ([child11image isEqualToString:#"Maghrib"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child11image isEqualToString:#"Isha"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child22 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:0]; [childButton4 setAlpha:0];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
label2.text = child22;
if ([child22image isEqualToString:#"Fajar"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Zuhr"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Asr"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Maghrib"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Isha"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child33 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:1]; [childButton4 setAlpha:0];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
label3.text = child33;
if ([child33image isEqualToString:#"Fajar"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Zuhr"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Asr"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Maghrib"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Isha"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child44 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:1]; [childButton4 setAlpha:1];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
label4.text = child44;
if ([child44image isEqualToString:#"Fajar"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Zuhr"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Asr"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Maghrib"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Isha"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child55 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:1]; [childButton4 setAlpha:1];
[childButton5 setAlpha:1]; [childButton6 setAlpha:0];
label5.text = child55;
if ([child55image isEqualToString:#"Fajar"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Zuhr"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Asr"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Maghrib"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Isha"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child66 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:1]; [childButton4 setAlpha:1];
[childButton5 setAlpha:1]; [childButton6 setAlpha:1];
label6.text = child66;
if ([child66image isEqualToString:#"Fajar"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Zuhr"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Asr"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Maghrib"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Isha"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else {
[childButton1 setAlpha:0]; [childButton2 setAlpha:0]; [childButton3 setAlpha:0]; [childButton4 setAlpha:0];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
}
The issue i found this code is if a condition occur like if ([child11 length] == 0) and if ([child11 length] !=0) the childButton1, childButton2 setAlpha: will be 1. I think you have to do the childButton1 setAlpha as 0 and childButton2 setAlpha as 1 if the above condition occures. I dont know what you exactly need
And one thing. Don't write codes just like this. Use switch cases and enumes to improve the code readability and performance. happy coding.

If [child11 length] != 0 you will never reach the other else-if checks. (I am guessing child11 and child22 can be non empty.
And you must improve your code! Start by learning examples of basic iphone apps spread all over the network.

Related

How to prevent scrollViewDidScroll getting call when View loads?

I have UITableView and its delegates are set via xib as shown in below image.
I have put some LOAD MORE CODE in method so that when user scrolldown, it sends request to server and load more values.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(#"Veer Suthar Scrolling the view");
CGPoint offset = scrollView.contentOffset;
CGRect bounds = scrollView.bounds;
CGSize size = scrollView.contentSize;
UIEdgeInsets inset = scrollView.contentInset;
float y = offset.y + bounds.size.height - inset.bottom;
float h = size.height;
float reload_distance = 15;
if(y > h + reload_distance)
{
//Call the Method to load More Data...
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
if ([appDelegate.reach isReachable])
{
if (onceCallTheLoadMore) {
onceCallTheLoadMore = NO;
int startCountValue = [vouchersArray count]+1;
int endCountValue = [vouchersArray count] + 10;
startCount = [[NSString alloc] initWithString:[NSString stringWithFormat:#"%d", startCountValue]];
endCount = [[NSString alloc] initWithString:[NSString stringWithFormat:#"%d", endCountValue]];
NSString *totalCount = [[NSUserDefaults standardUserDefaults] valueForKey: #"totalCountOfFeaturedVouchers"];
int totalCountValue = [totalCount intValue];
if (endCountValue > totalCountValue) {
////
onceCallTheLoadMore = YES;
}else{
[self featuredWebService];
}
//Veer, call here method for load more
}else{
}
}
}
}
Here this methods gets called when View Loads.
how can I prevent it from calling when view loads.
I tried
[self.tableview setDelegate:nil]; //Used in ViewWillAppear and again in ViewDidLoad its set to SELF.
But its not working fine.
ViewDidLoad COde is
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
if( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )480 ) < DBL_EPSILON ){
[self.tableView setFrame:CGRectMake(0, 64,320, 390)];
}else{
NSLog(#"ViewDidAppear is laoded ");
[self.tableView setFrame:CGRectMake(0, 64,320, 455)];
}
}
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
[self.view setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nev_top_right_title.png"] forBarMetrics:UIBarMetricsDefault];
UIButton *locationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *locationBtnImage = [UIImage imageNamed:#"map.png"] ;
//[backBtn setTitle:#"Back" forState:UIControlStateNormal];
[locationBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
// [backBtn setValue:[UIFont boldSystemFontOfSize:13.0] forKey:#"font"];
[locationBtn setBackgroundImage:locationBtnImage forState:UIControlStateNormal];
[locationBtn addTarget:baseViewController action:#selector(locationBtnPressed) forControlEvents:UIControlEventTouchUpInside];
locationBtn.frame = CGRectMake(0, 0, 41, 35);
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:locationBtn] ;
self.navigationItem.leftBarButtonItem = leftButton;
UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *searchBtnImage = [UIImage imageNamed:#"search.png"] ;
//[backBtn setTitle:#"Back" forState:UIControlStateNormal];
[searchBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
// [searchBtn setValue:[UIFont boldSystemFontOfSize:13.0] forKey:#"font"];
[searchBtn setBackgroundImage:searchBtnImage forState:UIControlStateNormal];
[searchBtn addTarget:baseViewController action:#selector(searchBtnPressed) forControlEvents:UIControlEventTouchUpInside];
searchBtn.frame = CGRectMake(0, 0, 39, 30);
UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithCustomView:searchBtn] ;
self.navigationItem.rightBarButtonItem = rightBtn;
UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 25.0)];
UIImageView *logo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"title_logo_ipad.png"]];
[logo setFrame:CGRectMake(62.0, -6.0, 62.0, 33.0)];
[titleView addSubview:logo];
//[titleView addSubview:title];
self.navigationItem.titleView = logo;
[self.navigationController.navigationBar subviews];
[titleView release];
[leftButton release];
[rightBtn release];
// [title release];
[logo release];
[(UITableView *)[self view] setSeparatorColor:[UIColor clearColor]];
}
else {
[(UITableView *)[self view] setSeparatorStyle:UITableViewCellSeparatorStyleNone];
UIEdgeInsets inset = UIEdgeInsetsMake(44, 0, 0, 0);
self.tableView.contentInset = inset;
self.tableView.scrollIndicatorInsets = inset;
[self.view setBackgroundColor:[UIColor clearColor]];
}
onceCallTheLoadMore = YES;
int startCountValue = [vouchersArray count]+1;
int endCountValue = [vouchersArray count] + 10;
startCount = [[NSString alloc] initWithString:[NSString stringWithFormat:#"%d", startCountValue]];
endCount = [[NSString alloc] initWithString:[NSString stringWithFormat:#"%d", endCountValue]];
self.vouchersArray = [[NSMutableArray alloc] initWithCapacity:0];
self.parser = [[[TBXMLParser alloc] init] autorelease];
parser.delegate = self;
self.arrFeaturedVouchers = [[NSMutableArray alloc]initWithCapacity:0];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
if ([appDelegate.reach isReachable])
{
[self performSelector:#selector(featuredWebService) withObject:nil afterDelay:0.1];
}
}
ViewWIllAPpear Code
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.view setBackgroundColor:[UIColor clearColor]];
if(voucherType == kVoucherTypeFeatured)
{
UIButton *locationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *locationBtnImage = [UIImage imageNamed:#"b_icon.png"] ;
//[backBtn setTitle:#"Back" forState:UIControlStateNormal];
[locationBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
// [backBtn setValue:[UIFont boldSystemFontOfSize:13.0] forKey:#"font"];
[locationBtn setBackgroundImage:locationBtnImage forState:UIControlStateNormal];
// Edited by Sugam on 19 Dec 2012
[locationBtn addTarget:[[UIApplication sharedApplication] delegate] action:#selector(locationBtnPressed) forControlEvents:UIControlEventTouchUpInside];
locationBtn.frame = CGRectMake(0, 0, 41, 35);
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:locationBtn] ;
self.navigationItem.leftBarButtonItem = leftButton;
[leftButton release];
}
UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *searchBtnImage = [UIImage imageNamed:#"seach_top.png"] ;
//[backBtn setTitle:#"Back" forState:UIControlStateNormal];
[searchBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
// [searchBtn setValue:[UIFont boldSystemFontOfSize:13.0] forKey:#"font"];
[searchBtn setBackgroundImage:searchBtnImage forState:UIControlStateNormal];
// Edited by Sugam on 19 Dec 2012
[searchBtn addTarget:[[UIApplication sharedApplication] delegate] action:#selector(searchBtnPressed) forControlEvents:UIControlEventTouchUpInside];
searchBtn.frame = CGRectMake(0, 0, 39, 30);
UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithCustomView:searchBtn] ;
self.navigationItem.rightBarButtonItem = rightBtn;
UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 25.0)];
UIImageView *logo;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
logo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"title_logo.png"]];
}
else
{
logo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"title_logo_ipad.png"]];
}
[logo setFrame:CGRectMake(62.0, -6.0, 62.0, 33.0)];
[titleView addSubview:logo];
//[titleView addSubview:title];
self.navigationItem.titleView = logo;
[self.navigationController.navigationBar subviews];
[titleView release];
// [title release];
[logo release];
[rightBtn release];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
[self.tabBarController showTabBar];
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
if( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )480 ) < DBL_EPSILON ){
[self.tableView setFrame:CGRectMake(0, 64,320, 390)];
}else{
NSLog(#"ViewDidAppear is laoded ");
[self.tableView setFrame:CGRectMake(0, 64,320, 455)];
}
}
}
dispatch_async(dispatch_get_main_queue(), ^{
/* Do somthing here with UIKit here */
_iconDownloader = [[ImageCache alloc] init];
_iconDownloader.delegate = self;
startCount = [[NSString alloc] initWithString:[NSString stringWithFormat:#"0"]];
endCount = [[NSString alloc] initWithString:[NSString stringWithFormat:#"10"]];
[Flurry logEvent:#"Featured Section Browse" timed:YES]; //How long the user has spent on the app
[self getLocation];
AppDelegate *app = (AppDelegate*) [[UIApplication sharedApplication]delegate];
self.arrFeaturedVouchers = (NSMutableArray*) [app.dbCommunicator getAllFeaturedVouchers];
if ([self.arrFeaturedVouchers count]>0)
{
[self.vouchersArray removeAllObjects];
for (int i = 0; i<[self.arrFeaturedVouchers count]; i++)
{
FeaturedVoucher *aFeaturedVoucher = [self.arrFeaturedVouchers objectAtIndex:i];
Voucher *aVoucher = [app.dbCommunicator getVoucherInfoForCampaignId:aFeaturedVoucher.featuredCampaignId];
if(aVoucher)
{
[self.vouchersArray addObject:aVoucher];
////
}
}
[self.arrFeaturedVouchers removeAllObjects];
[self.tableView reloadData];
}
});
}
Any suggestion
Thanks in Advance.
In your viewWillApear method, you have [self.tableView reloadData] - this is causing the scrollView to call its delegate scrollViewDidScroll

When Im moving view picked from cloudScrollView not showing the picked view in front

Adding UIImageView on UIScrollView and adding UIPanGestureRecognizer to it
UIImageView* lbl = [[UIImageView alloc]init];
NSString* tempStr = [NSString stringWithFormat:#"images/%#",[self.cloudArray objectAtIndex:i]];
NSString* imgPath = [self appendDocumentDirectoryPath:tempStr];
lbl.image = [[[UIImage alloc] initWithContentsOfFile:imgPath] autorelease];
[lbl setUserInteractionEnabled:YES];
//add gestures
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(moveImage:)];
[panGesture setMinimumNumberOfTouches:1];
[panGesture setMaximumNumberOfTouches:1];
[lbl addGestureRecognizer:panGesture];
[panGesture release];
CGSize expectedLabelSize = CGSizeMake(150, height);
lbl.frame = CGRectMake(pntX, pntY, expectedLabelSize.width, height);
[rectFrame addObject:[NSValue valueWithCGRect:lbl.frame]];
lbl.tag = i;
[cloudScrollView addSubview:lbl];
[lbl release];
lbl = nil;
pntX = pntX + space + expectedLabelSize.width;
[cloudScrollView setContentSize:CGSizeMake([cloudArray count]*170, 160)];
#pragma mark METHOD TO CATCH MOVE GESTURE EVENTS
- (void)moveImage:(UIPanGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateChanged) {
location1 = [gesture locationInView:cloudScrollView];
view1 = [gesture view];
if (isFirstTime) {
isFirstTime = NO;
draggedTag = view1.tag;
}
[view1 setCenter:CGPointMake(location1.x, location1.y)];
}
if (gesture.state == UIGestureRecognizerStateEnded) {
CGPoint pnt = [gesture locationInView:customTableView];
NSIndexPath* indexPath = [customTableView indexPathForRowAtPoint:pnt];
NSLog(#"indexpath = %d",indexPath.row);
if (index >= 0) {
[self.ansArray replaceObjectAtIndex:indexPath.row withObject:[self.cloudArray objectAtIndex:draggedTag]];//[self.cloudArray objectAtIndex:draggedTag]
[customTableView reloadData];
}
CGRect draggedItemRect = [[rectFrame objectAtIndex:draggedTag] CGRectValue];
view1.frame = draggedItemRect;
isFirstTime = YES;
}
}

Scroll view delegate methods app is crashing in iPAD 1st generation

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.

UIScrollView content not updating

I have UIScrollView in stage and paging functionality enabled to move back/next.
I have added 10 subviews in UIScrollView. When I have modify the content inside the subviews, then it is not reflected in UIScrollView.
Book.m
- (void) initializeWithXML:(NSString *)XMLURLString {
NSData *xmlData;
NSString *url;
if ( ![applicationData getMode] ) {
resourceRootURL = [[applicationData getAssetsPath] stringByAppendingPathComponent:#"phone/"];
} else {
resourceRootURL = [applicationData getAssetsPath];
}
url = [resourceRootURL stringByAppendingPathComponent:XMLURLString];
//NSLog(#"Root URL...%#", url);
if ([url rangeOfString:#"http"].location != NSNotFound) {
xmlData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
} else {
xmlData = [NSData dataWithContentsOfFile:url];
}
bookContentArray = [self grabXML:xmlData andQuery:#"//page"];
// view controllers are created lazily
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++) {
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];
for(int i = 0; i < [bookContentArray count]; i++) {
[viewControllers addObject:[NSNull null]];
}
if ( isTwoPage ) {
kNumberOfPages = [bookContentArray count];
} else {
kNumberOfPages = [bookContentArray count]/2;
}
CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
scrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
scrollView.pagingEnabled = YES;
scrollView.backgroundColor = [UIColor blackColor];
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.contentSize = [self contentSizeForPagingScrollView];
scrollView.contentSize = CGSizeMake(scrollView.contentSize.width,scrollView.frame.size.height);
scrollView.delegate = self;
self.view = scrollView;
kNumberOfPages = [bookContentArray count];
pageControl.numberOfPages = kNumberOfPages;
pageControl.currentPage = 0;
// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
[self loadPage:0];
}
- (void) loadPage:(int)number {
// Calculate which pages are visible
int firstNeededPageIndex = MAX(number-1, 0);
int lastNeededPageIndex = MIN(number+1, [viewControllers count] - 1);
//NSLog(#"%d,%d",firstNeededPageIndex,lastNeededPageIndex);
// Recycle no-longer-visible pages
for(int i = 0; i < [viewControllers count]; i++) {
ImageScrollView *page = [viewControllers objectAtIndex:i];
if ((NSNull *)page != [NSNull null]) {
if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
//NSLog(#"removed page %d", page.index);
[page removeImages];
[page removeFromSuperview];
page = nil;
[viewControllers replaceObjectAtIndex:i withObject:[NSNull null]];
}
}
}
// load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
if ( number == 0 ) {
[self loadScrollViewWithPage:number];
[self loadScrollViewWithPage:number+1];
} else if ( number == [bookContentArray count]-1) {
[self loadScrollViewWithPage:number-1];
[self loadScrollViewWithPage:number];
} else {
[self loadScrollViewWithPage:number-1];
[self loadScrollViewWithPage:number];
[self loadScrollViewWithPage:number+1];
}
}
- (void)loadScrollViewWithPage:(int)page {
ImageScrollView *pageController = [[ImageScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
pageController.index = page;
pageController.myDelegate = self;
pageNumber = pageControl.currentPage;
pageController.isTwoPage = isTwoPage;
if ( pageNumber == page ) {
pageController.isCurrentPage = YES;
} else {
pageController.isCurrentPage = NO;
}
[controller setImageURL:leftURL andRightURL:rightURL andPriority:0];
[scrollView addSubview:controller];
}
ImageScrollView.m
- (void) setImageURL:(NSString *)leftURL andRightURL:(NSString *)rightURL andPriority:(int)priority {
[imageView removeFromSuperview];
[imageView release];
imageView = nil;
if ( !isTwoPage ) {
imageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
} else {
imageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
}
if ( isTwoPage ) {
leftImage = [[FBEPage alloc] initWithNibName:#"FBEPage" bundle:nil];
leftImage.view.frame = CGRectMake(0, 43, 512, 682);
rightImage = [[FBEPage alloc] initWithNibName:#"FBEPage" bundle:nil];
rightImage.view.frame = CGRectMake(512, 43, 512, 682);
} else {
leftImage = [[FBEPage alloc] initWithNibName:#"FBEPage" bundle:nil];
leftImage.view.frame = imageView.frame;
rightImage = [[FBEPage alloc] initWithNibName:#"FBEPage" bundle:nil];
rightImage.view.frame = imageView.frame;
}
leftImage.delegate = self;
rightImage.delegate = self;
if ( isFirstPage ) {
[leftImage.view setHidden:YES];
[rightImage.view setHidden:NO];
} else if ( isLastPage ) {
[leftImage.view setHidden:NO];
[rightImage.view setHidden:YES];
} else if ( !isTwoPage ) {
[leftImage.view setHidden:NO];
[rightImage.view setHidden:YES];
} else {
[leftImage.view setHidden:NO];
[rightImage.view setHidden:NO];
}
imageView.backgroundColor = [UIColor whiteColor];
[self addSubview:imageView];
[leftImage setImageURL:leftURL];
[rightImage setImageURL:rightURL];
[imageView addSubview:leftImage.view];
[imageView addSubview:rightImage.view];
}
FBPage.m
- (void) setImageURL:(NSString *)url {
imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(0, 0, 768, 1024);
imageView.center = self.view.center;
imageView.userInteractionEnabled = TRUE;
[container addSubview:imageView];
[activityIndicator setHidden:YES];
if ([url rangeOfString:#"http"].location != NSNotFound) {
SDWebImageManager *manager = [SDWebImageManager sharedManager];
UIImage *cachedImage = [manager imageWithURL:[NSURL URLWithString:url]];
if (cachedImage) {
[imageView setImage:cachedImage];
isImageLoaded = YES;
[self addScrollView];
} else {
[activityIndicator setHidden:NO];
[activityIndicator startAnimating];
[manager downloadWithURL:[NSURL URLWithString:url] delegate:self options:0 success:^(UIImage *image){
[activityIndicator stopAnimating];
[activityIndicator setHidden:YES];
[imageView setImage:image];
isImageLoaded = YES;
[self addScrollView];
} failure:nil];
}
imageURL = url;
} else {
imageView.image = [UIImage imageWithContentsOfFile:url];
isImageLoaded = YES;
[self addScrollView];
}
}
- (void) setHotspotURL:(NSString *)URL {
[hotspot.view removeFromSuperview];
[hotspot release];
hotspot = nil;
hotspot = [[FBHotspot alloc] initWithNibName:#"FBHotspot" bundle:nil];
hotspot.view.frame = CGRectMake(0, 0, 768, 1024);
hotspot.delegate = self;
[hotspot setURL:URL];
[container addSubview:hotspot.view];
}
**When I am calling setHotspotURL and it’s not updating to the scrollview.**
Make sure you inserted your content at the correct position within the scroll view. Set the contentSize accordingly. Try to call layoutSubviews of the UIScrollView instance

how to stop the animation at the last frame?

How I can stop animation on the last frame.
Code here:
- (void)method{
NSMutableArray *images = [[NSMutableArray alloc]init];
NSInteger i;
for (i = 0; i < 75; i++){
NSString *str = [NSString stringWithFormat:#"pictures%i.png", i];
UIImage *img =[UIImage imageNamed:str];
[images addObject:img];
}
// Begin the animation
somePicture = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"8Ball_003_00075.png"]];
//somePicture = [[[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)] autorelease];
//[somePicture isAnimating]==0;
somePicture.frame = CGRectMake(0, 0, 320, 480);
[somePicture setAnimationImages:images];
somePicture.animationDuration = 5.0f;
somePicture.animationRepeatCount = 1;
[somePicture startAnimating];
somePicture.center = CGPointMake(160.0f, 230.0f);
//[images release];
[NSTimer scheduledTimerWithTimeInterval: 0.5f target: self selector: #selector(tick) userInfo: nil repeats: YES];
[self.view addSubview:somePicture];
}
-(void)tick{
if(![somePicture isAnimating]) { [timer invalidate]; [somePicture stopAnimating]; timer=nil; NSLog(#"#ye1111eah!!!");}
else
NSLog(#"#y");}
I know that I must used NSTimer but i don't know how :(
Why do you allocate somePicture twice
somePicture = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"8Ball_003_00075.png"]];
somePicture = [[[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)] autorelease];
Can't you just use this
somePicture = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"8Ball_003_00075.png"]];
somePicture.frame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
UPDATE
I think this will do it
- (void)method{
NSMutableArray *images = [[NSMutableArray alloc]init];
NSInteger i;
for (i = 0; i < 75; i++){
NSString *str = [NSString stringWithFormat:#"pictures%i.png", i];
UIImage *img =[UIImage imageNamed:str];
[images addObject:img];
}
// Begin the animation
somePicture = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"8Ball_003_00075.png"]];
somePicture.frame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
self.view addSubview:somePicture];
//[somePicture isAnimating]==0;
[somePicture setAnimationImages:images];
somePicture.animationDuration = 5.0f;
somePicture.animationRepeatCount = 1;
somePicture.center = CGPointMake(160.0f, 230.0f);
[somePicture startAnimating];
[self performSelector:#selector(tick) withObject:self afterDelay:5.0];
}
- (void)tick
{
[somePicture stopAnimating];
if(![somePicture isAnimating])
{
NSLog(#"#ye1111eah!!!");
}
else
NSLog(#"#y");
}
hope this helps