Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help on update and delete sqlite on the tableview
    primarykey
    data
    text
    <p>I'm a beginner on xcode and I have very little knowledge about it. Here is my code. I'm doing a simple account management program for iOS 6.0. I need to select the row from where i'm going to edit/delete my data from the table view and then be able to update/delete it. I don't know how to code those and I need help from experienced programmers. My project: <a href="http://www.mediafire.com/?95l8pwzu3c62ts0" rel="nofollow">http://www.mediafire.com/?95l8pwzu3c62ts0</a></p> <pre><code>#import "FlipsideViewController.h" @interface FlipsideViewController () @end @implementation FlipsideViewController @synthesize entries; - (void)viewDidLoad { self.label.text=self.strUsername; entries = [[NSMutableArray alloc]init]; [self openDB]; NSString *sql = [NSString stringWithFormat:@"SELECT * FROM SUMMARY8 WHERE theuser = '%s'",[self.label.text UTF8String]]; sqlite3_stmt *statement; if (sqlite3_prepare(account, [sql UTF8String], -1, &amp;statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW){ char *field1=(char *) sqlite3_column_text(statement, 0 ); NSString *field1Str = [[NSString alloc]initWithUTF8String:field1]; char *field2=(char *) sqlite3_column_text(statement, 1 ); NSString *field2Str = [[NSString alloc]initWithUTF8String:field2]; char *field3=(char *) sqlite3_column_text(statement, 2 ); NSString *field3Str = [[NSString alloc]initWithUTF8String:field3]; char *field4=(char *) sqlite3_column_text(statement, 3 ); NSString *field4Str = [[NSString alloc]initWithUTF8String:field4]; NSString *str = [[NSString alloc]initWithFormat:@"%@ - %@ - %@", field1Str,field3Str,field4Str]; [entries addObject:str]; } } [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(NSString *) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[paths objectAtIndex:0]stringByAppendingPathComponent:@"account.sql"]; } -(void) openDB { if (sqlite3_open([[self filePath] UTF8String], &amp;account) !=SQLITE_OK){ sqlite3_close(account); NSAssert(0,@"Database failed to open"); } else { NSLog(@"database opened"); } } - (IBAction)addaccount:(id)sender { MainViewController *FVC = [self.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"]; FVC.strUsername=self.strUsername; [self presentViewController:FVC animated:YES completion:nil]; // FVC.label.text=self.label.text; } - (IBAction)btnEdit:(id)sender { } - (IBAction)btnDelete:(id)sender { [self tableView:&lt;#(UITableView *)#&gt; cellForRowAtIndexPath:&lt;#(NSIndexPath *)#&gt;]; } #pragma mark - Actions - (IBAction)done:(id)sender { [self.delegate flipsideViewControllerDidFinish:self]; } -(NSInteger) numberOfSectionsInTableView: (UITableView *)tableView { return 1; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *myTitle = [[NSString alloc]initWithFormat:@"Name - Username - Password"]; return myTitle; } -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"%d", [entries count]); return [entries count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {//NSLog(@"test"); static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.textLabel.text = [self.entries objectAtIndex:indexPath.row]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *selectedRow = [entries objectAtIndex:indexPath.row]; NSString *sql = [NSString stringWithFormat:@"DELETE FROM SUMMARY8 WHERE name = '%@'",selectedRow]; char *err; if (sqlite3_exec(account, [sql UTF8String], NULL, NULL, &amp;err)!=SQLITE_OK){ sqlite3_close(account); NSAssert(0, @"Could not delete row"); } else { NSLog(@"row deleted"); UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Done" message:@"Account was deleted successfully!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } } @end </code></pre> <p>is this correct? sorry I absolutely have no background on Xcode. So sorry for the bother..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload