新しいエントリボタンを押すたびに、そのボタンを押した時間とともに newcell が表示される UITableView が必要な iOS アプリを作成しようとしています。私の問題は、ボタンを押すたびに、作成されたセルに現在の時刻が表示されるだけでなく、別の時刻を表示していたその上のセルがリロードされ、現在の時刻も表示されることです。わかりやすく説明すると、8:05、9:01、および 9:10 にボタンを押すと、UITableView に次のように表示されます。
-8:05
-9:01
-9:10
代わりに、次のように表示されます。
-9:10
-9:10
-9:10.
私は何をしますか??ありがとう
これが私のコードです( newEntry はボタンで、brain は現在の時刻を取得する方法があるオブジェクトです)
@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