私はxcodeの初心者であり、それについての知識はほとんどありません。これが私のコードです。iOS6.0用の簡単なアカウント管理プログラムを実行しています。テーブルビューからデータを編集/削除する行を選択してから、データを更新/削除できるようにする必要があります。それらをコーディングする方法がわからないので、経験豊富なプログラマーの助けが必要です。私のプロジェクト:http ://www.mediafire.com/?95l8pwzu3c62ts0
#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, &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], &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:<#(UITableView *)#> cellForRowAtIndexPath:<#(NSIndexPath *)#>];
}
#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, &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
これは正しいです?申し訳ありませんが、Xcodeのバックグラウンドはまったくありません。ご迷惑をおかけして申し訳ありません。