我从 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];
}
}
}
}
}