tags:

views:

122

answers:

3

alt text Hey all,

I am trying to accomplish something very simple yet getting an error and it's driving me nuts.

here is what I am doing:

Function 1:

-(id)initWithText:(NSString *)text1 :(NSString *)text2 :(NSString *)text3 :(NSString *)text4 :(NSString *)text5

{

here I do the assignment. I have not initialized the NSString date, projectName, task, duration and comment, but I don't see that causing any trouble.

 date=text1;
 projectName=text2;
 task=text3;
 duration=text4;

 if ([text5 isEqualToString:@"Add Comment"]==TRUE || [text5 isEqualToString:@""]==TRUE) 
 {
  comment=@"No Comment";
 }    

 else {
  comment=text5;
 }

date, duration, task ,projectname, comment are all NSString type.

This function gets called in a different viewController using the statement:

Function1 Call:

[self.summaryViewController initWithText:self.dateDisplay.text :self.projectNameDisplay.text:self.taskDisplay.text:self.durationDisplay.text:commentText.text];

where dateDisplay, projectNameDisplay, taskDisplay, durationDisplay are all UILabels and commentText is a UITextView


now I try to save the values captured through the function into a database using another function.

Function2:

-(void) insertValues:(NSString *)text1 :(NSString *)text2 :(NSString *)text3 :(NSString *)text4 :(NSString *)text5
{

 if([self openDB]==TRUE)

   {
    NSString *sql  = [NSString stringWithFormat:@"INSERT INTO mastertable(_date,_projectName,_task,_duration,_comment,_status) VALUES ('%@','%@','%@','%@','%@','Pending');",text1, text2, text3, text4, text5];

    char *err;

    NSLog(sql);

  if(sqlite3_exec(database,[sql UTF8String], NULL, NULL, &err) !=SQLITE_OK)
   {

    NSAssert(0, @"error inserting values into table");
    sqlite3_close(database);
   }

   else
   {
    NSLog(@"Entry Made");

                sqlite3_close(database);

   }


 }
}

Function2 call:

[master insertValues:date :projectName :task :duration :comment];

My insert into table query, when printed in NSLog, throws up this:

INSERT INTO mastertable(_date,_projectName,_task,_duration,_comment,_status) VALUES (' Aug 26, 2010',' Staffing',' Mentoring',' 01:01',

'( > )'

,'Pending');

I think it's because of the conversion of UITextView to NSString

Please help

Sayeed

A: 

UITextViews text property has NSString as return value, so that should not be the Problem

Gauloises
@ GauloisesWhen I printing the insert query in log this is what I am getting:INSERT INTO mastertable(_date,_projectName,_task,_duration,_comment,_status) VALUES (' Aug 26, 2010',' Staffing',' Mentoring',' 01:01','( <UILabel: 0x3947700; frame = (10 0; 280 39); text = 'Comment : rer...'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x3947760>>)','Pending');
Bogus Boy
as Suriya already asked, please show us some code of you getting the NSString from the textfield, the problem is most likely there
Gauloises
Please check the second block of the code. I have made a few amends
Bogus Boy
Hey, I think I have made some headway. When I receive the value in a textView rather than receiving it in NSString and pass textView.text as argument, it works. Can you guys figure it out now ? Please check!!
Bogus Boy
how do you "recieve" the value? Show some code of that please, as i said, there might be your problem.
Gauloises
I mean, instead of doing NSString *str=(UITextView *) commentText.text; which is behaving horrendously if I do (UITextView *) commentText1.text;=(UITextView *) commentText.text; and pass commentText1.text as an argument to my insert query, it works fine.
Bogus Boy
A: 

Make sure the UITextField is properly initialized. Looks like it is pointing somewhere into memory.

tob
I inserted the textView using the Interface builder. How do I initialize it now?
Bogus Boy
Is the connection to the IBOutlet set properly?
tob
Hey, I am trying to insert breakpoint and check.Sometimes it is showing "Variable is not a CFString"
Bogus Boy
Most likely that it is not connected. Check if the connection is present in Interface Builder.
tob
I have checked in the Interface builder. It's connected. I have changed a few of its properties through code. Couldn't have done it without a connection.Now I am trying to write the text field data in a label before I save it. The label gets the value right when I print it in the log,NSLog(label.text);but when I pass this label.text as argument to my insert query, it gets a null value.Sayeed
Bogus Boy
Hey, I think I have made some headway. When I receive the value in a textView rather than receiving it in NSString and pass textView.text as argument, it works. Can you guys figure it out now ? Please check!!
Bogus Boy
Can you give some more detail on that? What do you mean by "receive"?
tob
I mean, instead of doing NSString *str=(UITextView *) commentText.text;which is behaving horrendouslyif I do (UITextView *) commentText1.text;=(UITextView *) commentText.text;and pass commentText1.text as an argument to my insert query, it works fine.
Bogus Boy
Sure, you are casting `commentText.text` to `UITextView` but it is of type `NSString`. That cannot work.`NSString *str=commentText.text` is the way to do it. No need for any casts.
tob
A: 

@ tob,

Hey, tob I wrote the wrong code. Actually, I am not doing any casting; I am just initializing. And here is the code:

I have a UITextView commentText.text and I am extracting it's contents once the user feeds it to store it in NSString *str. NSString *str= commentText.text;

which is behaving horrendously. When I try retrieving the value stored in str i get weird messages like "CA Layer 1048w@#" and when I insert breakpoints to check it says variable not a CFString.

However, if I create another UITextView commentText2.text just like the first one and set its size to zero as I don't want it on my screen and I do this,

commentText2.text=commentText.text;

and pass commentText2.text as the argument for my insert query, the value gets saved in the database right and is retrieved right. Have I expressed myself?

Bogus Boy