私は私が私がテーブルビューのデータソース方式でどのように多くのセクションを返しています、考えるようになったアップデート中にtableViewに実際にいたどのように多くの行やセクションプリントアウトしてみました...そして、これが犯人でした:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 0;
}
あなたが1と0でない
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
に戻ってきていることを確認し、少なくともこの...
私のための問題を解決しました
UPDATE:それはしばらくの間、働いていた後、私は再び同じ問題を抱えている
。私は少しアプリを修正した。私の最初のビューはtableViewで、右上のプラスボタンをクリックすると、情報を入力できる別のテーブルが表示されます。 [完了]をクリックすると、情報がこのコードのコアデータモデルに追加されます。
- (IBAction)doneButtonPressed:(UIBarButtonItem *)sender
{
MoneyBadgeAppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context =
[appDelegate managedObjectContext];
NSManagedObject *newMoment;
newMoment = [NSEntityDescription
insertNewObjectForEntityForName:@"SpendingMoment"
inManagedObjectContext:context];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *modifiedDate = [dateFormat dateFromString: self.dateTextField.text];
[newMoment setValue: modifiedDate forKey:@"date"];
[newMoment setValue: descTextField.text forKey:@"desc"];
[appDelegate.eventsArray insertObject:newMoment atIndex:0];
NSError *error;
[context save:&error];
[self dismissViewControllerAnimated:YES completion:nil];
}
そして、私はそれが戻ったときに私のviewDidAppear方法では、次のコンソールに印刷することで成功したコアデータモデルに入れます確認しました最初の画面に戻ります。
-(void)viewDidAppear:(BOOL)animated{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SpendingMoment"
inManagedObjectContext:self.managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *items = [self.managedObjectContext
executeFetchRequest:fetchRequest error:&error];
for (SpendingMoment *moment in items) {
NSLog(@"Date: %@, Desc: %@", [moment date], [moment desc]);
}
[self addEvent];
そして、私のaddEventメソッドは、この行います。問題はこの時点で何
- (void)addEvent {
[self.tableScreen beginUpdates];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableScreen insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableScreen reloadData];
[self.tableScreen endUpdates];
@try{
[self.tableScreen scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
@catch(NSException *exception){
}
}
任意のアイデア?ありがとう!
私はすでにそれを行いました。 [timeZoneNames insertObject:@ "HELLO" atIndex:0]; 行数は常に1以上です。このエラーが発生します。 – insomiac
numberOfRowsInSectionの戻り値の型は[timeZoneNames count]です。 beginUpdatesとendUpdatesを使用せずにinsertRowsAtIndexPathsを使用しても問題ありませんか? – insomiac
@Aby '-beginUpdates'のドキュメント:以降の挿入、削除、および選択操作(たとえば、cellForRowAtIndexPath:とindexPathsForVisibleRows)を同時にアニメーション化する場合は、このメソッドを呼び出します。複数のUI操作を1つのUI操作にグループ化するために使用されます。操作は1つのみです。 –