0

I need to create multiple buttons in UIWebView. So, i used tag for button. And i save the button tag to database with INTEGER . But it's not saving proper value. Each button tag having text in database. Later i need to retrieve. But after storing last value to database and click anyother button it fetching only last updated value. Why this happen?

Table:

textnotes          text_id   button_id

  hi                1         1
  how are you       1         3
im fine             2         7
  This is test       2         11

UIButton:

int gTag = 1;
webviewbutton.tag = gTag;
 gTag++;

[wbCont.scrollView  addSubview:webviewbutton];

Insert:

const char *sqlInsert = [[NSString stringWithFormat:@"insert into textnote (textnotes,text_id,button_id ) values ('%@','%@','%ld')", txtview.text,artID,(long)webviewbutton.tag] cStringUsingEncoding:NSUTF8StringEncoding];

Retrieve button tag with text from database:

    textArray=[[NSMutableArray alloc]init];

        webbutton_art=[[NSMutableArray alloc]init];

        webbutton_button=[[NSMutableArray alloc]init];

    if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
    const char *sql =  [[NSString stringWithFormat:
                                     @"SELECT textnotes,text_id,button_id FROM textnote where button_id = '%ld' AND text_id = '%@' ",(long)webviewbutton.tag,artID]cStringUsingEncoding:NSUTF8StringEncoding];


                NSLog(@"sql is %s",sql);

                sqlite3_stmt *statement;

                if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {

                    while (sqlite3_step(statement) == SQLITE_ROW) {

                        txtstring = [[NSString alloc] initWithUTF8String:
                                     (const char *) sqlite3_column_text(statement, 0)];


                        webbutton_textartid = sqlite3_column_int(statement, 1);

                        webbutton_buttontag= sqlite3_column_int(statement, 2);

          [textArray addObject:txtstring];

         [webbutton_art addObject:@(webbutton_textartid)];

                        [webbutton_button addObject:@(webbutton_buttontag)];


    if( webbutton_art  && webbutton_button ){

    for(int i=0;i<[textArray count];i++){


txtview = [[UITextView alloc]initWithFrame:CGRectMake(0,0,320,568)];

        txtview.font = [UIFont fontWithName:@"Helvetica" size:12];


             txtview.text=[textArray objectAtIndex:i];

 [self.view addSubview:txtview];

             }



    }
4

1 回答 1

0

声明一个整数变量,如:

int offset;

然后这样做:

for (int i = 0; i<[textArray count]; i++) {



        UITextView *txtview = [[UITextView alloc]initWithFrame:CGRectMake(100,100+offset,320,568)];

        txtview.font = [UIFont fontWithName:@"Helvetica" size:12];


        txtview.text=[textArray objectAtIndex:i];

        [self.view addSubview:txtview];

        offset = offset + 50;
    }
于 2013-11-08T05:18:16.390 回答