1

您好我正在尝试输入一个 NSMutable 数组并将其显示在表格视图中。最初数组是零。表视图是从另一个视图控制器调用的,数据是单例的。我正在使用第三类来输入额外的数组元素。Eerything 工作正常,除非我从三等舱点击后退按钮,而不是字符串值,单元格在表格视图中显示为黑色。单击特定单元格后,就会显示该值。如果我取消选择它,单元格将再次变为黑色。如果有人能帮助我我的餐桌课是

@implementation stocktable

#pragma mark -
#pragma mark View lifecycle

-(void)insertaobject{

    stockname *s1 = [[stockname alloc]init];
    [self.navigationController pushViewController:s1 animated:YES];
    [s1 release];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

 [self.navigationController setNavigationBarHidden:NO];


 UIBarButtonItem *addbutton = [[UIBarButtonItem alloc]
 initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertaobject)];
 self.navigationItem.rightBarButtonItem = addbutton;
 [addbutton release];
    [[NSNotificationCenter defaultCenter]addObserver:self selector: @selector(addthestocks:) name:@"someevent" object: nil];

}


-(void)addthestocks:(NSNotification*)notification{

    if ([[notification name]isEqualToString:@"someevent"]) {
        //[self.navigationController.visibleViewController reloadInputViews];
        [self.tableView reloadData];
    }

}




#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    int i = 1;
    return i;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [[[stockdata sharedarray] stocksymbols]count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        cell.textLabel.text = [[[stockdata sharedarray] stocksymbols] objectAtIndex:indexPath.row];
        //[self.thedatamodel.stocksymbols objectAtIndex:indexPath.row];
    }

    // Configure the cell...

    return cell;
}

第三类是

@implementation stockname

@synthesize txt1;
@synthesize label2;
@synthesize button1;


-(IBAction)textfieldoneediting:(id)sender{
    [sender resignFirstResponder];
    label2.text = txt1.text;
    NSString* stkk = [[NSString alloc]initWithString:txt1.text];
    [[[stockdata sharedarray]stocksymbols] addObject:stkk];
    if ([[[stockdata sharedarray]stocksymbols]count]>0) {
        NSLog(@",,%@",[[[stockdata sharedarray]stocksymbols]objectAtIndex:0]);
    }

    [[NSNotificationCenter defaultCenter]postNotificationName:@"someevent" object: self];

}

-(IBAction)startediting:(id)sender{

    [sender becomeFirstResponder];



}
4

0 回答 0