0

Hello friends I am developing application in which view has one textField & 2 buttons. When user clicks on "Add" then text from textfield should be stored in datatabse. When user clicks on "Display"then data fetched from database should be displayed in textField. The code written is like this

//SettingsApplicationViewController.h

#import "FMDatabase.h"

@interface SettingsApplicationViewController : UIViewController {

    FMDatabase *db;

    IBOutlet UITextField *urlField;

    IBOutlet UIButton *insertButton;

    IBOutlet UIButton *displayButton;

}

@property(nonatomic, retain) IBOutlet UITextField *urlField;

@property(nonatomic, retain) IBOutlet UIButton *insertButton;

@property(nonatomic, retain) IBOutlet UIButton *displayButton;

-(void)insertButtonClicked :(id)sender;

-(void)displayButtonClicked:(id)sender;

-(id)initApp;


@end

//  SettingsApplicationViewController.m

    #import "SettingsApplicationViewController.h"
#import "FMDatabase.h"

@implementation SettingsApplicationViewController


@synthesize urlField;

@synthesize insertButton;

@synthesize displayButton;

-(id)initApp

{

    if(![super init])
        return nil;

    //DB stored in application bundle
    NSString *DBName = @"SettingDB.sqlite";
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingString:DBName];

    db = [FMDatabase databaseWithPath:path];
    [db setLogsErrors:TRUE];
    [db setTraceExecution:TRUE];

    if(![db open])
    {
        NSLog(@"Could not open Database");
        return 0;
    }

    else
    {
        NSLog(@"Database opened successfully");
    }
    return self;
}


    - (void)viewDidLoad {
    [super viewDidLoad];
    [self initApp];
}


    -(void)insertButtonClicked :(id)sender
{

[db executeUpdate:@"insert into Settings values (?)",urlField.text];
    [self resignFirstResponder];

}

    -(void)displayButtonClicked:(id)sender

{

    NSString *returnResult = [[NSString alloc]init];
    FMResultSet *rs = [db executeQuery:@"select url from Settings"];
    while ([rs next])
    {
        returnResult = [rs stringForColumn:@"url"];
        [urlField setText:returnResult];
    }


}

// SettingDB.sqlite

CREATE TABLE Settings(url text(50));

I created connections in IB & copied libsqlite3.dylib & FMDatabase file. I dont know why " # " is not printed in this post but I have # in my code.

When I compile this code it is showing 1 error as follows

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

Please help me friends. Thanks

Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152
iOSAppDev
  • 2,755
  • 4
  • 39
  • 77

2 Answers2

1

This error is usually displayed when you are referring to a file in Xcode and that file not in the mentioned path. (That file will be shown red in the Project Navigator)

Avinash
  • 51
  • 3
0

Have you assigned Action for those buttons?

If not do as follows,

Instead of -(void)insertButtonClicked :(id)sender; use -(IBAction)insertButtonClicked :(id)sender; and assign them to respective button action.

or else,

In viewdidLoad,

[insertButton addTarget:self action:@selector(insertButtonClicked:)   forControlEvents:UIControlEventTouchUpInside]; 
[displayButton addTarget:self action:@selector(displaytButtonClicked:)   forControlEvents:UIControlEventTouchUpInside]; 
KingofBliss
  • 15,055
  • 6
  • 50
  • 72
  • i tried what u suggested still there is same error => Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1 – iOSAppDev Feb 22 '11 at 17:25
  • check this post http://stackoverflow.com/questions/1248520/gcc-4-2-failed-with-exit-code-1-iphone – KingofBliss Feb 22 '11 at 17:40
  • @ KingofBliss => I am not getting any warning. Just 1 error mentioned. – iOSAppDev Feb 23 '11 at 03:34
  • There may be some file which has no refference . You can see that type of file in red letter. Remove that file. – KingofBliss Feb 23 '11 at 04:47