2014-10-09 78 views
0

我在將數據從unwind segue變爲NSMutableArray對象時遇到了一些麻煩。當我將NSLog從unwind segue中取出時,它顯示信息存在,它只是不會在我的數組中顯示在表視圖中。我的問題是什麼?感謝大家。將Segue放到一個NSMutableArray對象中

#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; 
} 
+0

因此,如果您登錄self.arrayNames作爲unwindSegueToChoices最後一行它表明capitalizedString不添加(或者你只是沒有看到它在你的表格視圖)? – rdelmar 2014-10-10 00:15:06

回答

1

您需要添加新項陣列後重新加載表視圖:

[self.tableView reloadData]; 
+0

你是一個拯救生命的人。非常感謝。 – Josh 2014-10-10 01:18:23

相關問題