在视图内滚动视图

发布于 2024-12-23 12:47:00 字数 1659 浏览 0 评论 0原文

我需要你的帮助。基本上我在主视图控制器中创建了一个小的滚动视图和一个页面控件。现在,当按下滚动视图内的按钮时,我会丢失 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文