I have a code in the viewDidLoad and others method, and i want to reload them if i click on a button, i already try the setNeedDisplay but it doesn’t work, i don’t know if i using it in the right sens?
This my code in the 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;
.....
}
This is the action that i want to use for reloading the 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];
}
}
[self.view setNeedsDisplay];doesn’t invoke the[self viewDidLoad];.And, we don’t call
viewDidLoadmanually. I suggest that move the code which you want to invoke into another method and invoke that method in bothviewDidLoadand the method binding with your button.