Disabling the UIButton on Scroll View Change
Hi I am trying to implement Photos.app开发者_高级运维 like application, in which on the below toolbar we can have the page change buttons for scrolling. So, I have put one button for scrolling to the first page and one button for the last page. And two buttons for next and previous pages scrolling.
[[self.toolbarItems lastObject] setEnabled:NO];
I am changing the state of the button items by putting something similar to the above line of code. But this requires for me to keep track of the page number's and the buttons whose status needs to the changed. e.g If I am on the last page then , the last page button needs to disable but it has to be enabled in other pages.
Is there a better way of changing the button status based on the page number ? ( instead of counting pages and changing button status.)
Not fully sure I understand the question, but presumably you have to know what photo you're on. Make that a NSNumber property, then use a custom setter to know when the photo number is changing and adjust the buttons:
- (void) checkToolBar: (NSNumber *) pageNumber {
int page = [pageNumber intValue];
[[self.toolbarItems objectAtIndex:0] setEnabled: (page !=0)];
[[self.toolbarItems objectAtIndex:1] setEnabled: (page !=0)];
[[self.toolbarItems objectAtIndex:2] setEnabled: (page != [photos count]];
[[self.toolbarItems objectAtIndex:3] setEnabled: (page != [photos count]];
}
- (void)setNumPage:(NSNumber *)newPage {
if (numPage != newPage) {
[numPage release];
numPage = [newPage retain];
[self checkToolBar:numPage];
}
}
精彩评论