0

我从 UIWebView 获取触摸坐标并存储到数据库。后来我从数据库中获取这些值,如果这些值匹配,我在该坐标上创建一个按钮。我使用标签来创建按钮数量,但是当从 UIWebView 回来并转到 UIWebView 时,最后一个坐标按钮只显示所有其他按钮都没有显示。为什么?

if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
            // We "step" through the results - once for each row.
            while (sqlite3_step(statement) == SQLITE_ROW) {



                xff=sqlite3_column_double(statement, 0);

                yff=sqlite3_column_double(statement, 1);

                art_Id = sqlite3_column_int(statement, 2);

                NSLog(@"xff is %f",xff);

                NSLog(@"yff is %f",yff);

                //  NSLog(@"zc is %@",zc);

                NSLog(@"art_Id is %ld",(long)art_Id);


                    if(xff && yff && art_Id){

        NSLog(@"error");

        btnArray=[[NSMutableArray alloc]init];

        NSLog(@"xff is %f",xff);
        NSLog(@"yff is %f",yff);
        NSLog(@"art_idd is %ld",(long)art_Id);

        button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button1 addTarget:self
                    action:@selector(click1:)
          forControlEvents:UIControlEventTouchDown];
        [button1 setTitle:@"click" forState:UIControlStateNormal];

        button1.frame = CGRectMake(xff, yff, 30.0, 20.0);


        button1.tag = gTag;
        gTag++;

        [wbCont.scrollView  addSubview:button1];



    }




            }
        }
    }

我对 viewDidLoad 使用了相同的代码;

-(void)viewDidLoad{

if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
            // We "step" through the results - once for each row.
            while (sqlite3_step(statement) == SQLITE_ROW) {



                xff=sqlite3_column_double(statement, 0);

                yff=sqlite3_column_double(statement, 1);

                art_Id = sqlite3_column_int(statement, 2);

                NSLog(@"xff is %f",xff);

                NSLog(@"yff is %f",yff);

                //  NSLog(@"zc is %@",zc);

                NSLog(@"art_Id is %ld",(long)art_Id);



    if(xff && yff && art_Id){

        NSLog(@"error");


        NSLog(@"xff is %f",xff);
        NSLog(@"yff is %f",yff);
        NSLog(@"art_idd is %ld",(long)art_Id);

        button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button1 addTarget:self
                    action:@selector(click1:)
          forControlEvents:UIControlEventTouchDown];
        [button1 setTitle:@"click" forState:UIControlStateNormal];

        button1.frame = CGRectMake(xff, yff, 30.0, 20.0);


        button1.tag = gTag;
        gTag++;

        [wbCont.scrollView  addSubview:button1];

        }




            }
        }
    }




}
4

1 回答 1

0

我不明白你在帖子中的第一部分代码是做什么的。

无论如何,从您的 viewDidLoad 代码中,我假设您将获得多个按钮的坐标(x,y)集,并且您希望在该位置创建按钮。

在您的代码中,您没有在任何循环中创建按钮,这意味着您只创建了一个按钮。我的理解是,在您的 while 循环中,您仅采用 x 和 y 坐标,您还需要在此循环内创建按钮。

只需尝试在while (sqlite3_step(statement) == SQLITE_ROW)循环中添加此代码

button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 addTarget:self
               action:@selector(click1:)
               forControlEvents:UIControlEventTouchDown];
[button1 setTitle:@"click" forState:UIControlStateNormal];
button1.frame = CGRectMake(xff, yff, 30.0, 20.0);
button1.tag = gTag;
gTag++;

[wbCont.scrollView  addSubview:button1];
于 2013-10-29T08:57:06.957 回答