Graphics Programs Reference
In-Depth Information
@interface ListViewController : UITableViewController
{
RSSChannel *channel;
ListViewControllerRSSType rssType;
}
In
ListViewController.m
, add a
UISegmentedControl
to the
naviga-
tionItem
that will change the
rssType
.
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
UIBarButtonItem *bbi =
[[UIBarButtonItem alloc] initWithTitle:@"Info"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(showInfo:)];
[[self navigationItem] setRightBarButtonItem:bbi];
UISegmentedControl *rssTypeControl =
[[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:@"BNR", @"Apple", nil]];
[rssTypeControl setSelectedSegmentIndex:0];
[rssTypeControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[rssTypeControl addTarget:self
action:@selector(changeType:)
forControlEvents:UIControlEventValueChanged];
[[self navigationItem] setTitleView:rssTypeControl];
[self fetchEntries];
}
return self;
}
Then, in
ListViewController.m
, implement
changeType:
, which will be sent to
the
ListViewController
when the segmented control changes.
- (void)changeType:(id)sender
{
rssType = [sender selectedSegmentIndex];
[self fetchEntries];
}
Finally, modify
fetchEntries
in
ListViewController.m
to make the appropri-
ate request to the store depending on the current
rssType
. To do this, move the comple-
tion block into a local variable, and then pass it to the right store request method. (The
code that needs to be executed when either request finishes is the same.) This method will
now look like this:
- (void)fetchEntries