您正在尝试输入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];
}