UIScrollView to jump particular page - iphone

I have a scroll view containing webview and webview is displaying content from xml. for e.g i have 10 pages . so if a want to go particular page how should i go to that page
int j=myindex;
int k=0;
for (int i=0; i < [appDelegate.books count]; i++) {
if (j>i) {
// //j++;
continue;
}
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * k;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView*subView=[[UIView alloc ]initWithFrame:frame];
//subView.backgroundColor=[appDelegate.books objectAtIndex:i];
[self.scrollView addSubview:subView];
CGRect myframe=CGRectMake(8, 16, 371, 242);
UIImageView*imageView=[[UIImageView alloc] initWithFrame:myframe];
Book*aBook=[appDelegate.books objectAtIndex:i];
NSString*myimage=aBook.mainimgurl;
myimage = [myimage stringByReplacingOccurrencesOfString:#"\n" withString:#""];
myimage = [myimage stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:myimage]]];
j++;
imageView.image=image;
CGRect mywebframe=CGRectMake(0, 30, 768, 876);
UIWebView*webView=[[UIWebView alloc] initWithFrame:mywebframe];
/*NSString*title=aBook.title;
NSString*mytitle=#"Rask og grønn";
title = [title stringByReplacingOccurrencesOfString:#"\n" withString:#""];
title = [title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString*mytitle1=#"Fortidsklimaet på Svalbard";
if ([title isEqualToString:mytitle ] || [title isEqualToString:mytitle1]) {
htmlString=aBook.magazinenumberdescription;
}*/
if (aBook.fulltext==nil) {
htmlString=aBook.magazinenumberdescription;
}
else {
htmlString=aBook.fulltext;
}
//NSString*htmlString=aBook.description;
[webView loadHTMLString:htmlString baseURL:nil];
[subView addSubview:webView];
CGRect myframe1=CGRectMake(387, 16, 363, 292);
UITextView*textView=[[UITextView alloc] initWithFrame:myframe1];
textView.font=[UIFont fontWithName:#"Times New Roman" size:16];
NSString*description=aBook.description;
description = [description stringByReplacingOccurrencesOfString:#"\n" withString:#""];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:#"å" withString:#"å"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:#"ø" withString:#"ø"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:#"æ" withString:#"æ"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:#"Æ" withString:#"Æ"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:#"Ø" withString:#"Ø"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:#"&Aring" withString:#"Å"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
k++;
textView.text=description;
// [subView addSubview:textView];
// [subView addSubview:imageView];
}
//NSInteger numberofPages=10-j;
NSInteger numberofPages=[appDelegate.books count];
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * numberofPages, self.scrollView.frame.size.height);
[pageControl setNumberOfPages:numberofPages];
[pageControl setActivePageColor:[UIColor clearColor]];
[pageControl setInactivePageColor:[UIColor clearColor]];

try this :
- (void) viewDidLoad // Or any other method
{
[myScroll scrollRectToVisible:CGRectMake(320*pageNumber, 0, 320 , 240) animated:NO];
//320 is a width of my page,you have to replace it with your page's width
[self.view addSubview:myScroll];
}
hope this helps you..

Related

How to capitalized first letter of Label

Here's my code :-
I need to Change only the first letter of the Word to capitalized.
UILabel *lbl4=[[UILabel alloc]initWithFrame:CGRectMake(10, 90, 200, 30)];
lbl4.text= [NSString stringWithFormat:#"(%#)", [arrtype objectAtIndex:0]];
lbl4.font = [UIFont fontWithName:#"Helvetica" size:18];
lbl4.textColor=[UIColor blackColor];
lbl4.backgroundColor=[UIColor clearColor];
Capitalization is for string not label
use
[NSString capitalizedString]
to capitalise a string and set it as text to the label
lbl4.text= [[NSString stringWithFormat:#"(%#)", [arrtype objectAtIndex:0]]capitalizedString];
NSString *abc = #"demo";
abc = [NSString stringWithFormat:#"%#%#",[[abc substringToIndex:1] uppercaseString],[abc substringFromIndex:1] ];
NSLog(#"abc = %#",abc);
Use this
UILabel *lbl4=[[UILabel alloc]initWithFrame:CGRectMake(10, 90, 200, 30)];
NSString *abc = [NSString stringWithFormat:#"(%#)", [arrtype objectAtIndex:0]];
abc = [NSString stringWithFormat:#"%#%#",[[abc substringToIndex:1] uppercaseString],[abc substringFromIndex:1]];
lbl4.text = abc;
lbl4.font = [UIFont fontWithName:#"Helvetica" size:18];
lbl4.textColor=[UIColor blackColor];
lbl4.backgroundColor=[UIColor clearColor];
- (NSString *) capitalizedFirstLetter:(NSString *)stringToConvert
{
NSString *retVal = stringToConvert;
if (stringToConvert.length <= 1)
{
retVal = stringToConvert.capitalizedString;
}else
{
retVal= [NSString stringWithFormat:#"%#%#",[[retVal substringToIndex:1] uppercaseString],[retVal substringFromIndex:1] ];
}
return retVal;
}
call this method:
[self capitalizedFirstLetter:labelName or textFieldName];

How to Access Particular view of a pageControl viewController?

Hi I m creating a project where multiple Images Loading from Server With some like Count and Comment Count and a Button to like the image. I m showing the individual Images With using a Slider Controller like PageControl.
this is My code for Showing the View
-(UIView*)reloadView:(DPSliderView *)sliderView viewAtIndex:(NSUInteger)idx
{
_loading_view.hidden=TRUE;
if (idx < [photos count]) {
NSDictionary *item = [photos objectAtIndex:idx];
PhotoView *v = [[PhotoView alloc] init];
v.photoIndex = idx;
v.imageView.imageURL = [DPAPI urlForPhoto:item[#"photo_220x220"]];
NSString *placename1 = [item valueForKeyPath:#"spotting.item.name"];
NSString *firstCapChar1 = [[placename1 substringToIndex:1] capitalizedString];
NSString *cappedString1 = [placename1 stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar1];
v.spotNameLabel.text = cappedString1;
NSString *placename = [item valueForKeyPath:#"spotting.place.name"];
NSString *firstCapChar = [[placename substringToIndex:1] capitalizedString];
NSString *cappedString = [placename stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar];
NSString *place1=[NSString stringWithFormat:#"%#",cappedString];
NSString *address=[NSString stringWithFormat:#"%#",[item valueForKeyPath:#"spotting.place.address"]];
NSString *location_str3 = [NSString stringWithFormat:#"# %#, %#",place1,address];
int cap_len=[place1 length];
int address_lenth=[address length];
ZMutableAttributedString *str = [[ZMutableAttributedString alloc] initWithString:location_str3
attributes:[NSDictionary dictionaryWithObjectsAndKeys:
[[FontManager sharedManager] zFontWithName:#"Lucida Grande" pointSize:12],
ZFontAttributeName,
nil]];
[str addAttribute:ZFontAttributeName value:[[FontManager sharedManager] zFontWithName:#"Lucida Grande" pointSize:12] range:NSMakeRange(0, cap_len+3)];
[str addAttribute:ZForegroundColorAttributeName value:[UIColor colorWithRed:241/255.0f green:73.0/255.0f blue:2.0/255.0f alpha:1.0]range:NSMakeRange(0, cap_len+3)];
[str addAttribute:ZForegroundColorAttributeName value:[UIColor colorWithRed:128.0/255.0f green:121.0/255.0f blue:98.0/255.0f alpha:1.0]range:NSMakeRange(cap_len+4, address_lenth)];
v.placefontlabel.zAttributedText=str;
v.likesCountLabel.text = [NSString stringWithFormat:#"%i", [item[#"likes_count"] intValue]];
if ([_device_lang_str isEqualToString:#"es"])
{
v.shightingsLabel.text = [NSString stringWithFormat:NSLocalizedString(#"%i Vistas", nil), [item[#"sightings_count"] intValue]];
}
else
{
v.shightingsLabel.text = [NSString stringWithFormat:NSLocalizedString(#"%i Sightings", nil), [item[#"sightings_count"] intValue]];
}
if ([nolocationstr isEqualToString:#"YES"])
{
v.distanceLabel.text =[NSString stringWithFormat:#"%.2f km", [item[#"distance"] floatValue]];
}
else
{
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:[[item valueForKeyPath:#"spotting.place.lat"]floatValue] longitude:[[item valueForKeyPath:#"spotting.place.lng"] floatValue]];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:[_explore_lat_str floatValue] longitude:[_explore_lng_str floatValue]];
NSString *lat_laong=[NSString stringWithFormat:#"%f",[location1 distanceFromLocation:location2]];
int km=[lat_laong floatValue]*0.001;
NSString *distancestr=[NSString stringWithFormat:#"%d km",km];
float dist=[distancestr floatValue];
v.distanceLabel.text = [NSString stringWithFormat:#"%.2f km", dist];
}
if (![item[#"likes"] boolValue]) {
v.likeButton.enabled = YES;
v.likeButton.tag = idx;
[v.likeButton setImage:[UIImage imageNamed:#"like_new.png"] forState:UIControlStateNormal];
[v.likeButton addTarget:self action:#selector(likeAction:) forControlEvents:UIControlEventTouchUpInside];
}
else
{
v.likeButton.tag = idx;
[v.likeButton setImage:[UIImage imageNamed:#"like_new1.png"] forState:UIControlStateNormal];
}
NSArray *guides = item[#"guides"];
if ([guides count] > 0) {
NSString *guideType = [[guides objectAtIndex:0] valueForKey:#"type"];
UIImage *guidesIcon = [UIImage imageNamed:[NSString stringWithFormat:#"%#.png", guideType]];
v.guideButton.hidden = NO;
v.guideButton.tag = idx;
[v.guideButton setImage:guidesIcon forState:UIControlStateNormal];
[v.guideButton addTarget:self action:#selector(guideAction:) forControlEvents:UIControlEventTouchUpInside];
}
v.shareButton.tag = idx;
[v.shareButton addTarget:self action:#selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(photoTapGesture:)];
[v addGestureRecognizer:tapGesture];
[tapGesture release];
return [v autorelease];
} else {
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sc_img.png"]];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.center = CGPointMake(CGRectGetMidX(iv.bounds), 110);
[indicator startAnimating];
[iv addSubview:indicator];
[indicator release];
return [iv autorelease];
}
}
Now My question is :
If i will Click on Like Button , Then i have to change the button image as well as like count. I can able to Change the Button Image By This Method
[sender setImage:[UIImage ImageNamed:#"image.png"]];
But How can I change the Like count of the Label ? How can i access the Particular label of the View ? I have assigned the tag But , I dont know how to assign it.I dont want to Reload Whole Slider as the Photo are loading from Network (Remote Server) . Thanks for your Time.
Just keep a reference to the label and update that.
// #interface
#property (nonatomic, strong) UILabel *myLabel;
// #implementation
_myLabel.text = #"Whatever.";
If you have multiple labels, set the tags when you create your views
newView.tag = sequenceNumber +100;
And then update
-(void)updateLabelWithTag:(NSInteger)tag {
UILabel *label = (UILabel*) [self.scrollView viewWithTag:tag];
label.text = #"Whatever.";
}

How to save image in data base loaded in ScrollView

I am using scroll view to load images in image view from array and then what ever image i want to save i am save to collection. So when i save image it always takes the pageNumber = 1 only I want that what ever page when add it only adds page which is at number one not others
-(void) loadNews{
NSURL*myurl=url;
myurl = [myurl stringByReplacingOccurrencesOfString:#"\n" withString:#""];
myurl = [myurl stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL*urlloaded= [[NSURL alloc]initWithString:myurl];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:urlloaded];
//Initialize the delegate.
RowTwoParser *parser = [[RowTwoParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
BOOL success = [xmlParser parse];
if(success)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
int k=0;
for (int i=0; i < [appDelegate.articles count]; i++) {
currentIndex=i;
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView*subView=[[UIView alloc ]initWithFrame:frame];
[self.scrollView addSubview:subView];
RowTwo*aRowTwo=[appDelegate.articles objectAtIndex:i];
CGRect mywebframe=CGRectMake(20, 60, 728, 800);
UIImageView*imageView=[[UIImageView alloc] initWithFrame:mywebframe];
NSString*thumb2=aRowTwo.image;
thumb2 = [thumb2 stringByReplacingOccurrencesOfString:#"\n" withString:#""];
thumb2 = [thumb2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL *url = [NSURL URLWithString:thumb2];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *image2 = [[UIImage alloc] initWithData:data];
imageView.image =image2 ;
[subView addSubview:imageView];
}
//NSInteger numberofPages=10-j;
NSInteger numberofPages=[appDelegate.articles count];
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * numberofPages, self.scrollView.frame.size.height);
CGRect frame;
//frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.x = self.scrollView.frame.size.width * myindex;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
[pageControl setNumberOfPages:numberofPages];
[pageControl setActivePageColor:[UIColor clearColor]];
[pageControl setInactivePageColor:[UIColor clearColor]];
}
-(IBAction)addToCollectionButtonAction{
GeoNewsAppDelegate *appDelegate = (GeoNewsAppDelegate *)[[UIApplication sharedApplication] delegate];
// Create a Coffee Object.
Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:0];
int pageNumber = [pageControl currentPage];
NSLog(collectionImage);
RowTwo*aRowTwo=[appDelegate.articles objectAtIndex:pageNumber];
NSString*thumb2=aRowTwo.image;
coffeeObj.thumb = thumb2;
coffeeObj.path = thumb2;
[appDelegate addCoffee:coffeeObj];
}
You need to enable paging for scroll view
self.scrollView.pagingEnabled = YES

How to next image in scroll view by next button in iphone

I have image in scroll view it is loading images from the array i also want this that when i press nextbutton next image should appear I have done following code for loading images in scrollview i want to go prevoius and next image by button click when i click next button it doesw not show next image
-(void) loadNews{
NSURL*myurl=url;
myurl = [myurl stringByReplacingOccurrencesOfString:#"\n" withString:#""];
myurl = [myurl stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL*urlloaded= [[NSURL alloc]initWithString:myurl];
//NSURL*url= [[NSURL alloc]initWithString:#"http://localhost:8888/RowOne.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:urlloaded];
//Initialize the delegate.
RowTwoParser *parser = [[RowTwoParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
BOOL success = [xmlParser parse];
if(success)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
int k=0;
for (int i=0; i < [appDelegate.articles count]; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView*subView=[[UIView alloc ]initWithFrame:frame];
[self.scrollView addSubview:subView];
RowTwo*aRowTwo=[appDelegate.articles objectAtIndex:i];
CGRect mywebframe=CGRectMake(20, 60, 728, 800);
UIImageView*imageView=[[UIImageView alloc] initWithFrame:mywebframe];
NSString*thumb2=aRowTwo.image;
thumb2 = [thumb2 stringByReplacingOccurrencesOfString:#"\n" withString:#""];
thumb2 = [thumb2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL *url = [NSURL URLWithString:thumb2];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *image2 = [[UIImage alloc] initWithData:data];
imageView.image =image2 ;
[subView addSubview:imageView];
k++;
}
//NSInteger numberofPages=10-j;
NSInteger numberofPages=[appDelegate.articles count];
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * numberofPages, self.scrollView.frame.size.height);
CGRect frame;
//frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.x = self.scrollView.frame.size.width * myindex;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
[pageControl setNumberOfPages:numberofPages];
[pageControl setActivePageColor:[UIColor clearColor]];
[pageControl setInactivePageColor:[UIColor clearColor]];
}
Next Button Code
-(IBAction)nextButton{
for (int nextIndex=[pageControl currentPage]; nextIndex < [appDelegate.articles count]; nextIndex++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * nextIndex;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView*subView=[[UIView alloc ]initWithFrame:frame];
[self.scrollView addSubview:subView];
RowTwo*aRowTwo=[appDelegate.articles objectAtIndex:nextIndex];
CGRect mywebframe=CGRectMake(20, 60, 728, 800);
UIImageView*imageView=[[UIImageView alloc] initWithFrame:mywebframe];
NSString*thumb2=aRowTwo.image;
thumb2 = [thumb2 stringByReplacingOccurrencesOfString:#"\n" withString:#""];
thumb2 = [thumb2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL *url = [NSURL URLWithString:thumb2];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *image2 = [[UIImage alloc] initWithData:data];
imageView.image =image2 ;
[subView addSubview:imageView];
// k+\
}
//NSInteger numberofPages=10-j;
NSInteger numberofPages=[appDelegate.articles count];
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * numberofPages, self.scrollView.frame.size.height);
CGRect frame;
//frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.x = self.scrollView.frame.size.width * myindex;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
[pageControl setNumberOfPages:numberofPages];
[pageControl setActivePageColor:[UIColor clearColor]];
[pageControl setInactivePageColor:[UIColor clearColor]];
}
If they are in scroll view, you use
CGPoint offset = CGPointMake(xPositionToScroll, yPositionToScroll);
[self.scrollView setContentOffset:topOffset animated:YES];
To some specific point.

UIScrollWith Clickable text

I have scrollview with two textview i want that on clicking any of the textview should go the desired information in the detail view
int j=0;
for (int i = 0; i < rowOne.count; i++) {
if (j==1) {
j++;
}
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView*subView=[[UIView alloc ]initWithFrame:frame];
[self.scrollView addSubview:subView];
Book*book=[rowOne objectAtIndex:i];
CGRect myframe=CGRectMake(107, 46, 258, 128);
UITextView*textView=[[UITextView alloc] initWithFrame:myframe];
book.bookID=bookidone;
textViewOneDescription=book.fulltext;
[subView addSubview:textView];
//[backViewButton addSubview:textView];
NSString* myid=book.bookID;
NSLog(myid);
NSString*text1=book.teaser;
fulltextone=book.fulltext;
textView.font=[UIFont fontWithName:#"Times New Roman" size:16];
NSString*mytext=book.teaser;
mytext = [mytext stringByReplacingOccurrencesOfString:#"\n" withString:#""];
mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext = [mytext stringByReplacingOccurrencesOfString:#"å" withString:#"å"];
mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext = [mytext stringByReplacingOccurrencesOfString:#"ø" withString:#"ø"];
mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext = [mytext stringByReplacingOccurrencesOfString:#"æ" withString:#"æ"];
mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext = [mytext stringByReplacingOccurrencesOfString:#"Æ" withString:#"Æ"];
mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext = [mytext stringByReplacingOccurrencesOfString:#"Ø" withString:#"Ø"];
mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext = [mytext stringByReplacingOccurrencesOfString:#"&Aring" withString:#"Å"];
mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
textView.text=mytext;
//testButton.tag=j;
//[testButton addTarget:self action:#selector(tappedItemAtIndex:)forControlEvents:UIControlEventTouchUpInside];
UIButton*headingButton=[UIButton buttonWithType:UIButtonTypeCustom];
headingButton.frame=CGRectMake(20, 10, 300, 35);
NSString*headingbuttontitle=book.title;
//NSString*headingbuttontitle=j;
headingbuttontitle = [headingbuttontitle stringByReplacingOccurrencesOfString:#"\n" withString:#""];
headingbuttontitle = [headingbuttontitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
[headingButton setTitle:headingbuttontitle forState:UIControlStateNormal];
//[headingButton setTitle:[NSString stringWithFormat:#"%d",j] forState:UIControlStateNormal];
[headingButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
headingButton.tag=j;
[headingButton addTarget:self action:#selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];
headingButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
headingButton.titleLabel.font = [UIFont boldSystemFontOfSize:20 ];
UIButton*myImageButton=[UIButton buttonWithType:UIButtonTypeCustom];
myImageButton.frame=CGRectMake(20, 46, 90, 127);
NSString*thumb2=book.thumbimgurl;
thumb2 = [thumb2 stringByReplacingOccurrencesOfString:#"\n" withString:#""];
thumb2 = [thumb2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
UIImage *image2 = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumb2]]];
myImageButton.tag=j;
[myImageButton setBackgroundImage:image2 forState:UIControlStateNormal];
// myImageView.image=[UIImage imageNamed:#"thumb.jpg"];
[myImageButton addTarget:self action:#selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];
[subView addSubview:myImageButton];
j++;
CGRect myframe1=CGRectMake(502, 46, 150, 128);
Book*book1=[rowOneSecond objectAtIndex:i];
UITextView*textViewtwo=[[UITextView alloc] initWithFrame:myframe1];
NSString*mytext1=book1.teaser;
textViewTwoDescription=book1.fulltext;
book1.fulltext=fulltexttwo;
book1.bookID=bookid;
testButton1.tag=j;
[testButton1 addTarget:self action:#selector(tappedItemAtIndex:)forControlEvents:UIControlEventTouchUpInside];
mytext1 = [mytext1 stringByReplacingOccurrencesOfString:#"\n" withString:#""];
mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext1 = [mytext1 stringByReplacingOccurrencesOfString:#"å" withString:#"å"];
mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext1 = [mytext1 stringByReplacingOccurrencesOfString:#"ø" withString:#"ø"];
mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext1 = [mytext1 stringByReplacingOccurrencesOfString:#"æ" withString:#"æ"];
mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext1 = [mytext1 stringByReplacingOccurrencesOfString:#"Æ" withString:#"Æ"];
mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext1 = [mytext1 stringByReplacingOccurrencesOfString:#"Ø" withString:#"Ø"];
mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
mytext1 = [mytext1 stringByReplacingOccurrencesOfString:#"&Aring" withString:#"Å"];
mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
textViewtwo.text=mytext1;
textViewtwo.font=[UIFont fontWithName:#"Times New Roman" size:16];
UIButton*headingButton1=[UIButton buttonWithType:UIButtonTypeCustom];
headingButton1.frame=CGRectMake(408, 10, 300, 37);
[headingButton1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
NSString*headingbutton1title=book1.title;
headingbutton1title = [headingbutton1title stringByReplacingOccurrencesOfString:#"\n" withString:#""];
headingbutton1title = [headingbutton1title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
headingButton1.titleLabel.font = [UIFont boldSystemFontOfSize:20 ];
[headingButton1 setTitle:headingbutton1title forState:UIControlStateNormal];
// [headingButton1 setTitle:[NSString stringWithFormat:#"%d",j] forState:UIControlStateNormal];
headingButton1.tag=j;
// [headingButton1 setTitle:j forState:UIControlStateNormal];
[headingButton1 addTarget:self action:#selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];
headingButton1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
UIButton*myImageButton1=[UIButton buttonWithType:UIButtonTypeCustom];
myImageButton1.frame=CGRectMake(408, 46, 90, 127);
NSString*thumb1=book1.thumbimgurl;
thumb1 = [thumb1 stringByReplacingOccurrencesOfString:#"\n" withString:#""];
thumb1 = [thumb1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
UIImage *image1 = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumb1]]];
myImageButton1.tag=j;
[myImageButton1 setBackgroundImage:image1 forState:UIControlStateNormal];
// myImageView.image=[UIImage imageNamed:#"thumb.jpg"];
[myImageButton1 addTarget:self action:#selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];
[subView addSubview:myImageButton1];
[subView addSubview:textViewOneLink];
[subView addSubview:headingButton];
[subView addSubview:headingButton1];
[subView addSubview:textViewtwo];
//[subView addSubview:textView];
}
You can not tap on textview. May be one work around is that add UIButton transparent on both the textview and implement IBAction for that.
Hope this tweak helps you.
You can code in this
-(void)textViewDidBeginEditing:(UITextView *)textView
{
//do something
}