2011-03-23 73 views
0

我正在研究一個應用程序,其中我在scrollview中添加了textview和一個按鈕。 正在根據數據庫的數據動態使用數組生成滾動視圖。 現在我想要做的是文本視圖應該隱藏在一個按鈕上,我已經添加在滾動視圖中。在滾動視圖中隱藏文本視圖

代碼.........

-load滾動視圖.....

- (無效)loadScrollView {

cxs=0; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"dreambuilder.sqlite"]; 
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) 
{ 
    const char *sql; 

    sql = "select dname, dream from dream order by dorder"; 
    //btnNextDream.enabled = FALSE; 
    sqlite3_stmt *statement; 
    statement = nil; 
    if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) 
    { 

     sqlite3_bind_int(statement, 1, objAppdelDreamDetail.intEditDream); 
     while (sqlite3_step(statement) == SQLITE_ROW) 
     { 

      btnItem = [[UIButton alloc]init]; 
      btnItem.backgroundColor=[UIColor clearColor]; 
      txtViewDescription = [[UITextView alloc]init]; 
      CGRect rect; 
      rect.origin.x = ((myScroll.frame.size.width - 320) /2) + cxs ; 
      rect.origin.y = 0; 
      rect.size.height = 460; 
      rect.size.width = 320; 
      [btnItem addTarget:self action:@selector(actionShowDreamImage:) forControlEvents:UIControlEventTouchUpInside]; 
      btnItem.frame = rect; 
      [btnItem setImage:[UIImage imageWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]]] forState:UIControlStateNormal]; 
      NSString *s=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)] ; 
      for(int i=0;i<[arrDream count];i++) 
      { 
       txtViewDescription.tag=i; 

      if ([s isEqual:@""]) { 
        txtViewDescription.frame=CGRectMake(rect.origin.x+15, 60, 300, 40); 
       }else { 
        CGSize textViewSize = [s sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(300, 460) lineBreakMode:UILineBreakModeWordWrap]; 
        txtViewDescription.frame=CGRectMake(rect.origin.x+15, 60, 300, textViewSize.height+10); 
        txtViewDescription.text=s; 
       } 
       txtViewDescription.alpha = 0.5; 
       txtViewDescription.layer.cornerRadius=10.0; 
       txtViewDescription.font=[UIFont fontWithName:@"Helvetica" size:18]; 
       txtViewDescription.backgroundColor=[UIColor blackColor]; 
       txtViewDescription.textColor=[UIColor whiteColor]; 
       txtViewDescription.editable = NO; 
       txtViewDescription.scrollEnabled=FALSE; 
      } 
      [myScroll addSubview:btnItem]; 
      [myScroll addSubview:txtViewDescription]; 
      [btnItem release]; 
      myScroll.scrollsToTop = NO; 
      [txtViewDescription release]; 
      cxs += myScroll.frame.size.width; 

     } 
    } 
    sqlite3_finalize(statement); 

} 
else 
{ 
    sqlite3_close(database); 
    NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database)); 
} 

[myScroll setContentSize:CGSizeMake(cxs, [myScroll bounds].size.height)]; 
if (intOID=1) { 
    btnPrevDream.enabled = FALSE; 

} 
int page; 
if(objAppdelDreamDetail.intPageCount>0) 
{ 
    page=objAppdelDreamDetail.intPageCount; 
    //NSLog(@"%d",page); 

} 
else 
{ 
    page=objAppdelDreamDetail.intPageCount; 
    //NSLog(@"%d",page); 
} 
[myScroll setContentOffset:CGPointMake(320 * page, 0) animated:YES]; 

}

按鈕事件...........

- (IBAction)actionShowDreamImage:(id)sender { if(!flgFaded) { tbarFooter.hidden = TRUE; tbarHeader.hidden = TRUE; lblNavTitle.hidden = TRUE; lblNavEdit.hidden = TRUE; lblNavPls.hidden = TRUE; //txtViewDescription.hidden = TRUE;

for(int i=1;i<[arrDream count];i++) 
    { 
     [[myScroll viewWithTag:1] setHidden:YES]; 
     txtViewDescription.tag=i; 
     txtViewDescription.hidden=TRUE; 

    } 

} 
else 
{ 
    tbarFooter.hidden = FALSE; 
    tbarHeader.hidden = FALSE; 
    lblNavTitle.hidden = FALSE; 
    lblNavEdit.hidden = FALSE; 
    lblNavPls.hidden = FALSE; 
    txtViewDescription.hidden = FALSE; 
} 
flgFaded = !flgFaded; 

}

+0

你能告訴我們什麼是不工作? – 2011-03-23 12:11:01

+0

@ Erik B ....所有代碼運行良好,我想隱藏所有文本查看是按鈕點擊事件。 – 2011-03-23 12:35:05

回答

0

只更改按鈕單擊事件方法

.............

-(IBAction)actionShowDreamImage:(id) sender { 

if(!flgFaded) 
    { 
     tbarFooter.hidden = TRUE; 
     tbarHeader.hidden = TRUE; 
     lblNavTitle.hidden = TRUE; 
     lblNavEdit.hidden = TRUE; 
     lblNavPls.hidden = TRUE; 
     for(int i=1;i<[arrDream count];i++) 

{ 

for(UITextView *txtview in myScroll.subviews) 

{ 

if(txtview.tag==i) 
       { 
        txtview.hidden=YES; 
       } 
      } 
     } 

    } 
    else 
    { 
     tbarFooter.hidden = FALSE; 
     tbarHeader.hidden = FALSE; 
     lblNavTitle.hidden = FALSE; 
     lblNavEdit.hidden = FALSE; 
     lblNavPls.hidden = FALSE; 
     for(int i=1;i<[arrDream count];i++) 
     { 
      for(UITextView *txtview in myScroll.subviews) 
      { 
       if(txtview.tag==i) 
       { 
        txtview.hidden=NO; 
       } 
      } 

     } 
    } 
    flgFaded = !flgFaded; 
} 
相關問題