2011-06-29 49 views
-1

我有兩個的TextView滾動型我想,上單擊任何的TextView的應該在詳細視圖中希望的信息UIScrollWith可點擊文本

詮釋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:@"&aring;" withString:@"å"]; 
    mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 
    mytext = [mytext stringByReplacingOccurrencesOfString:@"&oslash;" withString:@"ø"]; 
    mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 



    mytext = [mytext stringByReplacingOccurrencesOfString:@"&aelig;" withString:@"æ"]; 
    mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 


    mytext = [mytext stringByReplacingOccurrencesOfString:@"&AElig;" withString:@"Æ"]; 
    mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 


    mytext = [mytext stringByReplacingOccurrencesOfString:@"&Oslash;" 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:@"&aring;" withString:@"å"]; 
    mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 
    mytext1 = [mytext1 stringByReplacingOccurrencesOfString:@"&oslash;" withString:@"ø"]; 
    mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 



    mytext1 = [mytext1 stringByReplacingOccurrencesOfString:@"&aelig;" withString:@"æ"]; 
    mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 


    mytext1 = [mytext1 stringByReplacingOccurrencesOfString:@"&AElig;" withString:@"Æ"]; 
    mytext1 = [mytext1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 


    mytext1 = [mytext1 stringByReplacingOccurrencesOfString:@"&Oslash;" 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];   


} 
+0

代碼爲什麼你需要的TextView那裏呢? –

+0

你用UITextView Delegates試過了嗎? –

+0

textview顯示數據 – Ali

回答

0

您無法點擊textview。可能是一個解決方法是在textview上添加UIButton透明併爲此實現IBAction。

希望這個調整可以幫助你。

+0

我正在創建TextView的一個循環編程,如果添加的UIButton透明兩個TextView的IB中它僅給出最後的值我在這個問題做出讓上面的代碼,你明白 – Ali

+0

可以在循環創建的UIButton以及並給幀一樣textview.frame。確保在添加textview後將其添加到子視圖,以便它保持在textView的頂部。 – Deeps

+0

意味着如果我有UITextView textView – Ali

0

您可以在此

-(void)textViewDidBeginEditing:(UITextView *)textView 
    { 

//do something 

} 
+0

這是爲那些我們在IB創建,並通過出口 – Ali

+0

連接他們,我也貼出代碼同樣的問題上面PLZ告訴我解決 – Ali

+0

textView.delegate =自我; –