내 서버에 정보를 저장했습니다. JSON을 사용하여 데이터를 가져 왔습니다. 데이터는 가져와 장치 데이터베이스에 저장하고 가져옵니다. 문제는 cat_id = 1에서 일부 설정 이미지가 있다는 것입니다. & cat_id = 2에서 일부 이미지를 설정합니다. 이제 const char *sql = "SELECT id,cat_id,product_image FROM product where cat_id = '1'";
, const char *sql = "SELECT id,cat_id,product_image FROM product where cat_id = '2'";
같은 다른 이미지 집합에 대해 다른 Array를 사용하고 있습니다. "% @"를 사용하면 모든 값이 표시됩니다.데이터베이스에서 데이터 가져 오기
번호 : 화상
먼저 설정 : 이미지
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
const char *sql = "SELECT id,cat_id,product_image FROM product where cat_id = '1'";
NSLog(@"sql is %s",sql);
sqlite3_stmt *statement;
// int catID = 0;
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) {
catName = [[NSString alloc] initWithUTF8String:
(const char *) sqlite3_column_text(statement, 2)];
NSLog(@"catName is %@",catName);
[mArray addObject:catName];
[catName release];
// catID = sqlite3_column_int(statement, 0);
}
}
sqlite3_finalize(statement);
}
else {
sqlite3_close(database);
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
// Additional error handling, as appropriate...
}
초 설정 :
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
const char *sql = "SELECT id,cat_id,product_image FROM product where cat_id = '2'";
NSLog(@"sql is %s",sql);
sqlite3_stmt *statement;
// int catID = 0;
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) {
tabName = [[NSString alloc] initWithUTF8String:
(const char *) sqlite3_column_text(statement, 2)];
NSLog(@"tabName is %@",tabName);
[tabArray addObject:tabName];
[tabName release];
// catID = sqlite3_column_int(statement, 0);
}
}
sqlite3_finalize(statement);
}
else {
sqlite3_close(database);
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
// Additional error handling, as appropriate...
}
}
임 datas의 디스플레이 배열 ActionSheet 버튼 클릭을 이용하여 :
-(void)actionSheetClickedButtonAtIndex:(int)buttonIndex {
if (buttonIndex == 0) {
NSLog(@"button");
for (int i = 0; i<[mArray count]; i++) {
NSLog(@"index %d",i);
// imgView1=[[UIButton alloc]initWithFrame:CGRectMake(20+(i*74), 500, 72, 72)];
imgView1=[[UIButton alloc]initWithFrame:CGRectMake(20+(i*74), 0, 72, 72)];
Width = Width + 20+(i*74);
[imgView1 setTag:i+1];
[imgView1 addTarget:self action:@selector(arraysofsClicked:) forControlEvents:UIControlEventTouchUpInside];
[imgView1 setImage:((Mysof *)[mArray objectAtIndex:i]).photo forState:UIControlStateNormal];
[scrollview addSubview:imgView1];
// [myScroll addSubview:imgView1];
}
} else if (buttonIndex == 1) {
NSLog(@"button 1");
for (int i = 0; i<[tabArray count]; i++) {
NSLog(@"index %d",i);
// imgView1=[[UIButton alloc]initWithFrame:CGRectMake(20+(i*74), 500, 72, 72)];
imgView1=[[UIButton alloc]initWithFrame:CGRectMake(20+(i*74), 0, 72, 72)];
Width = Width + 20+(i*74);
[imgView1 setTag:i+1];
[imgView1 addTarget:self action:@selector(arraysofsClicked:) forControlEvents:UIControlEventTouchUpInside];
[imgView1 setImage:((Mysof *)[tabArray objectAtIndex:i]).photo forState:UIControlStateNormal];
[scrollview addSubview:imgView1];
// [myScroll addSubview:imgView1];
}
} else if (buttonIndex == 2) {
NSLog(@"button 2");
} else if (buttonIndex == 3) {
}
}
여기서 cat_id = 1 & cat_id = 2를 사용하고 싶지 않습니다. 나는 increament에 대한 매개 변수 값을 자동으로 전달하고 테이블에서 값을 가져와야합니다. 왜냐하면 내가 아무것도 바꾸면 cat_id가 증가하기 때문입니다.
귀하의 질문은 관련이없는 코드로 어수선하다. 코드 덤프를 줄이고 절대적으로 필요한 것만 표시하도록하십시오. 또한 문제가 무엇인지 정확하게 기술하십시오. – Mundi
메신저 데이터를 검색하는 데 cat_id를 사용합니다. 뭔가 편집하면 cat_id 번호가 바뀝니다. 그래서 cat_id = "% @"를 사용하면 모든 값을 얻게됩니다. 어떻게 루프 조건에 대한 매개 변수를 전달할 수 있습니다 .. – user2674668