i have a Person classs
@interface Person : NSObject
@property (nonatomic, strong) NSString * name;
@property (nonatomic, strong) NSString * area;
@property (nonatomic, strong) int pin;
- (id) initWithName:(NSString *)anName andAreaName:(NSString *)anArea andPin:(int)aPin;
First i am reading a sqlite DB and fetching the a list of data ie name,area & pin. Then i create an object of Person class & adding these fetched item in to it .Finally i add this object into an array.Now based on this array i am creating an table view & showing all these 3 data in different rows of a table view.
But now i have a Add New Name option is there on selection of which a pop up with text field will appear and on selection of submit option , a new row will be created with only name field in my table view.
So for this i have to update my old array or update initWithName: ?
Please guide me how to do this?
You can do this as follows,
Step 1:-
Create a Person object as follows,
Person *person = [[Person alloc] initWithName:@"Name" andAreaName:@"" andPin:0];
You can later add area
and pin
as,
person.area = @"Area";
person.pin = 10;
//or just do,
Person *person = [[Person alloc] initWithName:@"Name" andAreaName:@"Area" andPin:10];
//if you have Area and Pin already available, you can use the above line itself.
Step 2:-
Add this to data source array of table,
[self.array addObject:person];
Step 3:-
[self.tableView reloadData];//or do an insert row call on this tableview
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.