[英]Unwind Segue into an NSMutable Array
我在將數據從輕松的序列中導入NSMutableArray對象時遇到了一些麻煩。 當我不定期進行NSLog時,它表明信息在那里,只是沒有最終出現在我的數組中以表視圖顯示。 我怎么了 感謝大家。
#import "ChoicesViewController.h"
#import "MyDataChoices.h"
#import "AddChoiceViewController.h"
@interface ChoicesViewController () <UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (strong, nonatomic) NSMutableArray *arrayNames;
@property (strong, nonatomic) NSArray *sections;
@end
@implementation ChoicesViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
self.sections = [NSArray arrayWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V,", @"W", @"X", @"Y", @"Z", nil];
self.arrayNames = [[NSMutableArray alloc] init];
[self.arrayNames addObjectsFromArray:@[
[MyDataChoices itemWithNewName:@"Apples"],
[MyDataChoices itemWithNewName:@"Bread"]]];
}
- (IBAction)unwindSegueToChoices:(UIStoryboardSegue *)segue
{
AddChoiceViewController *sourceVC = segue.sourceViewController;
NSString *myNewItem = sourceVC.myTextField.text;
//NSString *myFinalString = [[myNewItem substringToIndex:1] capitalizedString];
NSString *capitalizedString = [myNewItem capitalizedString];
NSLog(capitalizedString);
//Why will this not work?
[self.arrayNames addObject:capitalizedString];
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *) tableView
{
return 1;
}
-(NSInteger) tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section
{
return self.arrayNames.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyDataChoices *currentRow = self.arrayNames[indexPath.row];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"mainCell2" forIndexPath:indexPath];
cell.textLabel.text = currentRow.myNameChoices;
return cell;
}
將新項目添加到數組后,您需要重新加載表視圖:
[self.tableView reloadData];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.