私はデータベースsqlite 3を持っているプロジェクトに取り組んでおり、そこにはテキスト用の3つの列があり、値を取得してビューに表示しています。text6 fields.しかし、私のコードでは、ユーザーが 3 つのテキスト フィールドのいずれか 1 つを入力でき、2 つを空白にすることができるという条件がありますが、値を取得しているときに、2 つのテキスト フィールドが空白値ではなく (null) を示す場合、どうすればこれを解決できますかデータをフェッチした後、nullではなく空白が表示されるように問題があります。ここにデータを挿入するための私のコードがあります
- (void)saveData
{
if ((txtfield.text.length==0)||(txtfield1.text.length==0)||(txtfield2.text.length==0)||(txtfield3.text.length==0)||(txtfield4.text.length==0))
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"fields can't be blank"
message:@"fill the fields"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
else{
NSString* gratitude2 = [NSString stringWithFormat:@"%@",txtfield3.text];
NSString* gratitude1 = [NSString stringWithFormat:@"%@",txtfield4.text];
NSString* title = txtfield.text;
NSString* date = txtfield1.text;
NSString* gratitude = [NSString stringWithFormat:@"%@",txtfield2.text];
[dbSingleton() createEditableCopyOfDatabaseIfNeeded];
[dbSingleton() insertdata:gratitude2 withgratitude1:gratitude1 title:title date:date gratitude:gratitude picture:imageDt audio:self.retrieveData];
}
ここでは、iPhoneのビューに表示します
-(void)gototree:(UIButton *)sender
{
int tag1=sender.tag;
[dbSingleton() createEditableCopyOfDatabaseIfNeeded];
NSMutableArray * array=[[NSMutableArray alloc]init];
array =[dbSingleton() getalldata:tag1];
NSString *gratitude22=[[array objectAtIndex:0]valueForKey:@"gratitude2"];
NSString *gratitude11=[[array objectAtIndex:0]valueForKey:@"gratitude1"];
NSString *title11 = [[array objectAtIndex:0]valueForKey:@"title"];
NSString *date11=[[array objectAtIndex:0]valueForKey:@"Date"];
NSString *gratitude=[[array objectAtIndex:0]valueForKey:@"gratitude"];
txtfield2=[[UITextField alloc]initWithFrame:CGRectMake(28, 164, 200,20)];
txtfield2.backgroundColor=[UIColor clearColor];
txtfield2.font=[UIFont fontWithName:@"Helvetica-Bold" size:13.0];
[self.view addSubview:txtfield2];
[txtfield2 setEnabled:NO];
txtfield2.text=gratitude;
txtfield3=[[UITextField alloc]initWithFrame:CGRectMake(28, 183, 200,20)];
txtfield3.backgroundColor=[UIColor clearColor];
txtfield3.font=[UIFont fontWithName:@"Helvetica-Bold" size:13.0];
[self.view addSubview:txtfield3];
[txtfield3 setEnabled:NO];
txtfield3.text=gratitude22;
txtfield4=[[UITextField alloc]initWithFrame:CGRectMake(28, 204, 200,20)];
txtfield4.backgroundColor=[UIColor clearColor];
txtfield4.font=[UIFont fontWithName:@"Helvetica-Bold" size:13.0];
[self.view addSubview:txtfield4];
[txtfield4 setEnabled:NO];
txtfield4.text=gratitude11;
}