我在viewDidLoad和其他方法中有一个代码,我想重新加载它们,如果我点击一个按钮,我已经尝试了setNeedDisplay但它不起作用,我不知道我是否在使用它对吗?
这是我在viewDidLoad中的代码:
- (void)viewDidLoad
{
// Create the UISegmentedControler "Next Review" and "Previouse Review"
UISegmentedControl *paginateReviewSegment = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Précedent",@"Suivant", nil]];
paginateReviewSegment.segmentedControlStyle = UISegmentedControlStyleBar;
[paginateReviewSegment addTarget:self action:@selector(paginateReviews:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *paginateBarButton = [[UIBarButtonItem alloc] initWithCustomView:paginateReviewSegment];
self.navigationItem.rightBarButtonItem = paginateBarButton;
[super viewDidLoad];
// Get the review selected
entryReview = [[entriesReview getEntries] objectAtIndex:self.reviewSelected];
// Resize the UIScrollView
[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:self.contentView.frame.size];
// Add UIView "Content" to UIScrollView
[self.scrollView addSubview:self.contentView];
// Set the user name
userNameLabel.text = entryReview.userName;
.....
}
这是我想用来重新加载UIView的动作:
- (void)paginateReviews:(UISegmentedControl*)sender
{
if (sender.selectedSegmentIndex == 0 && self.reviewSelected != 0)
{
self.reviewSelected -= 1;
entryReview = [[entriesReview getEntries] objectAtIndex:self.reviewSelected];
[self.view setNeedsDisplay];
} else if(sender.selectedSegmentIndex == 0 && self.reviewSelected != ([entriesReview entriesCount] - 1))
{
self.reviewSelected += 1;
entryReview = [[entriesReview getEntries] objectAtIndex:self.reviewSelected];
}
}
答案 0 :(得分:6)
[self.view setNeedsDisplay];
不会调用[self viewDidLoad];
。
而且,我们不会手动调用viewDidLoad
。我建议将要调用的代码移动到另一个方法中,并在viewDidLoad
和方法绑定中调用该方法。