我正尝试创建一个iOS应用程序,其中必须有一个UITableView,每次按下新的输入按钮时,按下该按钮。我的问题是,每次按下按钮时,不仅所创建的单元格显示当前时间,而且显示不同时间的单元格将重新加载并显示当前时间。为了尝试更好地解释它,如果我按下按钮在8:05,9:01和9:10,我想的UITableView显示:当我尝试创建一个新的单元格时,UITableview上的所有单元格都会发生更改
-8:05
-9:01
-9:10
相反,它显示:
-9:10
-9:10
-9:10.
我该怎么做?由于
这里是我的代码(newEntry是按钮和大脑是一个对象,我必须得到当前时间的方法)
@implementation MarcaPontoViewController{
NSMutableArray *_entryArray;
@synthesize brain=_brain;
- (void)viewDidLoad
{
[super viewDidLoad];
_brain = [[Brain alloc] init];
_entryArray = [[NSMutableArray alloc] init];
//[self updateTime];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [_entryArray count];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier= @"myCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [_entryArray lastObject];
}
return cell;
}
- (IBAction)newEntry:(id)sender {
[_entryArray addObject:[self.brain currentTime]];
[_timeTable reloadData];
}
@end
谢谢主席先生,你的帮助是非常apreciated。它现在工作:) – dietbacon 2013-03-17 02:42:49