に加え、UITableView
にオブジェクトを追加:間違ったオブジェクトは、私は<code>NSNotificationCenter</code>(別のコントローラを形成する)ことにより、オブジェクトを取得私のアプリでのUITableView
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(RosterSave:) name:@"RosterSave" object:nil];
}
-(void)RosterSave:(NSNotification *)notification
{
NewRoster* newRoster = [[NewRoster alloc]init];
newRoster = notification.object;
[myUser.rosterArray addObject:newRoster];
[self.myRoster reloadData];
}
をこれがのtableView方法であって、
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return myUser.rosterArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *iden = @"MyTable";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
}
NewRoster* myNewRoster = [myUser.rosterArray objectAtIndex:indexPath.row];
cell.textLabel.text = myNewRoster.nameRoster;
return cell;
}
ユーザは最初のオブジェクトを追加し、tableViewは自分の行を取得します。ユーザーが2番目のオブジェクトを追加すると、2番目のオブジェクトの2行がこのように追加されます。
この問題を解決するにはどうすればよいですか?
'RosterSave:'が何回呼ばれたか確認できますか?そして、 'myUser.rosterArray'を毎回チェックしますか? – Larme
あなたはどんな問題に直面していますか? – Feroz
答えを編集して、問題点を明確に指摘できますか? – EridB