在视图内滚动视图
我需要你的帮助。基本上我在主视图控制器中创建了一个小的滚动视图和一个页面控件。现在,当按下滚动视图内的按钮时,我会丢失 mainViewController 中每个属性的值。为了帮助您获得更清晰的了解,让我解释一下:
(NoteViewController.m)这是从滚动视图按下的按钮响应的操作
- (IBAction)removePerson:(UIButton *)sender {
MainViewController *remover = [[MainViewController alloc] init];
[remover removePersonWithPage:pageNumber];
[self.view removeFromSuperview];
[remover release]; }
(MainViewController.m)
- (void)removePersonWithPage:(int)page {
// The managedObjectContext is lost the moment it leaves MainViewController.m and goes to NoteViewController.m
// so you need to reload the managedObjectContext
if (managedObjectContext == nil)
{
managedObjectContext = [(OrdersAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}
// Get the list of people (Persons) from the managed Object Context
arrayOfPeople = [[NSMutableArray alloc] initWithArray:[self fetchDataWithEntity:@"Person" andSortKey:@"pageId"]];
// Find a specific person to delete using their page number and delete it finally remove it from array
NSManagedObject *personToDelete = [arrayOfPeople objectAtIndex:page];
[managedObjectContext deleteObject:personToDelete];
[arrayOfPeople removeObjectAtIndex:page];
// kNumberOfPages is replaced with the new number of people
kNumberOfPages = arrayOfPeople.count;
/* This is where problem occurs */
self.pageControl.numberOfPages = kNumberOfPages;
NSLog(@"The number of pages in the page control in remove is: %d", self.pageControl.numberOfPages);
[self saveObjectContext];
}
所以一切正常,但是当我到达最后的 NSLog 时,当它应该返回数据库中的页数时,它返回 0。我已经研究了好几天了,但无法弄清楚,请帮忙。谢谢
i need your help. Basically I created a small scrollView and a pageControl inside my main view controller. Now when ever a button inside a scroll view is pressed I lose the value of every property in my mainViewController. To help you get a clearer picture let me explain:
(NoteViewController.m) This is the action the button that is pressed from the scrollview responds to
- (IBAction)removePerson:(UIButton *)sender {
MainViewController *remover = [[MainViewController alloc] init];
[remover removePersonWithPage:pageNumber];
[self.view removeFromSuperview];
[remover release]; }
(MainViewController.m)
- (void)removePersonWithPage:(int)page {
// The managedObjectContext is lost the moment it leaves MainViewController.m and goes to NoteViewController.m
// so you need to reload the managedObjectContext
if (managedObjectContext == nil)
{
managedObjectContext = [(OrdersAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}
// Get the list of people (Persons) from the managed Object Context
arrayOfPeople = [[NSMutableArray alloc] initWithArray:[self fetchDataWithEntity:@"Person" andSortKey:@"pageId"]];
// Find a specific person to delete using their page number and delete it finally remove it from array
NSManagedObject *personToDelete = [arrayOfPeople objectAtIndex:page];
[managedObjectContext deleteObject:personToDelete];
[arrayOfPeople removeObjectAtIndex:page];
// kNumberOfPages is replaced with the new number of people
kNumberOfPages = arrayOfPeople.count;
/* This is where problem occurs */
self.pageControl.numberOfPages = kNumberOfPages;
NSLog(@"The number of pages in the page control in remove is: %d", self.pageControl.numberOfPages);
[self saveObjectContext];
}
So everything works but when I get to the NSLog at the end there, it returns 0 when it ought to be returning the number of pages in the database. I've been working on this for days now and can't figure it out, please help. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论