У меня есть база данных sqlite. Я читаю данные из базы данных с помощью команды SELECT
к таблице.
Я хочу добавить новую ячейку, содержащую несколько полей, в tableView и в базу данных.
Вот мой код (который не работает):
in RootViewController
- подготовка следующего просмотра
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller
SQLiteAppDelegate *appDelegate = (SQLiteAppDelegate *)[[UIApplication sharedApplication] delegate];
usersSale *us = (usersSale *)[appDelegate.usersSale1 objectAtIndex:indexPath.row];
if(self.detailView == nil) {
DetailViewController *viewController = [[DetailView alloc] initWithNibName:@"DetailViewViewController" bundle:nil];
self.animalView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.animalView animated:YES];
self.detailView.title = [us storeName];
self.detailView.txtProduct.text = [us saleSpecificProduct];
NSString *inStr = [NSString stringWithFormat:@"%d",us.saleMaxPrice];
self.detailView.txtPrice.text = inStr; //[us saleMaxPrice];
self.detailView.txtSaleNotes.text = [us saleNotes];
self.detailView.txtSaleCatagory.text = [us saleCatagory];
self.detailView.txtUserArrivalTime.text = [us userArrivalTime];
self.detailView.txtPublishDate.text = [us publishDate];
}
in DetailViewViewController
:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Sales Share"; // set title
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addItem:)];
self.navigationItem.rightBarButtonItem = addButton;
// match background color of table view
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
}
- (void)addItem:sender {
SQLiteAppDelegate *d = (SQLite AppDelegate *)[[UIApplication sharedApplication] delegate];
// registration para.
reg *rg = [[reg alloc]init];
NSString *myIDname = [rg initMyIDName] ;
NSString *myGender = [rg initMyGender] ;
//tableView array
Detail *an = [[Detail alloc]initWithName:5
saleStoreID:3
saleMaxPrice:77
saleSpecificProduct:txtProduct.text
saleCatagory:txtSaleCatagory.text
saleNotes:txtSaleNotes.text
userArrivalTime:txtUserArrivalTime.text
publishDate:txtPublishDate.text
publishTime:txtPublishTime.text
fAtMall:1
name:myIDname
gender:myGender
storeName:txtStoreName.text];
//sqlite d.b
[d inserUsersSaleltItem:an.saleSpecificProduct
saleCatagory:an.saleCatagory
saleNotes:an.saleNotes
userArrivalTime:an.userArrivalTime
publishDate:an.publishDate];
NSArray *array = [NSArray array];
NSNumber *num = [NSNumber numberWithInt:an.saleStoreID];
num = [NSNumber numberWithInt:an.saleMaxPrice];
NSString *string = an.saleSpecificProduct;
[d.usersSale1 addObject:string]; //string
string = an.saleCatagory;
[d.usersSale1 addObject:string]; //string
[d insertObject:array inListAtIndex:[d countOfList]];
[d.usersSale1 reloadData];
[self.navigationController dismissModalViewControllerAnimated:YES];
}