好的,我有7个NSMutableArrays,它们连接到tableview 第一个表视图告诉第二个表 - 视图加载哪一个, 它加载很好,但每个我想能够添加一个项目/单元格,但是 我只能为我的一个观点加载它。 这是我的NSMutableArrays项目和属性列表。
属性:
@property (nonatomic) NSMutableArray *Movies;
@property (nonatomic) NSMutableArray *Tv_Shows;
@property (nonatomic) NSMutableArray *Resturuants;
@property (nonatomic) NSMutableArray *Video_Games;
@property (nonatomic) NSMutableArray *Concert_Venues;
@property (nonatomic) NSMutableArray *Foods;
@property (nonatomic) NSMutableArray *Recipes
NSMutableArray项目
_Movies = [[NSMutableArray alloc]initWithObjects:@"Avatar", @"Kung Fu Panda", @"The Matrix", nil];
_Tv_Shows = [[NSMutableArray alloc]initWithObjects:@"Reguluar Show", @"Kung Fu Panda", @"Avatar The last Airbender", nil];
_Resturuants = [[NSMutableArray alloc]initWithObjects:@"Outback Steakhouse", @"Golden Corral", @"Wendy's", nil];
_Video_Games = [[NSMutableArray alloc]initWithObjects:@"black Ops", @"Call Of Duty", @"Modern Warfare", nil];
_Foods = [[NSMutableArray alloc]initWithObjects:@"Baked Bread", @"Pasta", @"Italian Meatballs", nil];
_Recipes = [[NSMutableArray alloc]initWithObjects:@"Chocolate Cookies", @"Brownies", @"Peanutbutter Fudge", nil];
_Concert_Venues = [[NSMutableArray alloc]initWithObjects:@"Pheonix", @"Buckeye", @"Maricopa", nil];
展开到列表方法只会加载第一个项目。
- (IBAction)unwindToTableViewController:(UIStoryboardSegue *)sender {
AddViewController *addViewController = (AddViewController *)sender.sourceViewController;
NSString *text = addViewController.textField.text;
//if NOT blank and NOT whitespace
if (![text length] == 0 && ![[text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
//Add it to the top of the data source.
[_Movies insertObject:text atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
//Insert it into the tableview
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
}
答案 0 :(得分:1)
//Add it to the top of the data source.
[_Movies insertObject:text atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
正如你所看到的,只有_movies被加载,你必须对_TvShows,Restaurants等做同样的事情......增加值(如不是0)。例如
[_Restaruants insertObject:text atIndex:1];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:1];
//you may have to keep inSection:0, try it with 1 anyway
答案 1 :(得分:1)
我明白了!
- (IBAction)unwindToTableViewController:(UIStoryboardSegue *)sender {
AddViewController *addViewController = (AddViewController *)sender.sourceViewController;
NSString *text = addViewController.textField.text;
//if NOT blank and NOT whitespace
if (![text length] == 0 && ![[text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
//Add it to the top of the data source.
[_Movies insertObject:text atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
//Insert it into the tableview
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
} 在_Movies下添加项目 像这样
[_Movies insertObject:text atIndex:0];
然后添加新的