【发布时间】:2011-05-03 02:28:36
【问题描述】:
我已经实现了一个 UISegmentControl 作为我的 detailViewController 的 rightBarButton。 此视图控制器显示从 UITableView 传递的信息。 这个 UITableView 的单元格填充了 CoreData 属性值。
我想要做的是让用户通过 detailViewController 在列表中上下移动。不必让用户不得不返回到 rootViewController,他们将获得通过 UISegmentControl 滚动浏览的能力。
我目前在 detailViewController.m 中有这个
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Setting up UISegmentedControl
// Segmented Control - Custom right bar button with a view
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@"arrowdown.png"],
[UIImage imageNamed:@"arrowup.png"],
nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 75, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
}
然后将其附加到以下方法,用于检测被点击的控件。
- (void)segmentAction:(id)sender
{
UISegmentedControl* segCtl = sender;
// the segmented control was clicked, handle it here
if([segCtl selectedSegmentIndex]==0){
NSLog(@"You clicked the down arrow - the segment clicked was %d", [segCtl selectedSegmentIndex]);
}else {
NSLog(@"You clicked the up arrow - the segment clicked was %d", [segCtl selectedSegmentIndex]);
}
}
我也很好奇是否有人知道如何检测是否还有可去的地方。也就是说,如果加载的音符在第一个位置,则禁用向下箭头,如果加载的音符在最后一个位置,则禁用向上箭头。这甚至可能吗?
任何帮助将不胜感激。
【问题讨论】:
标签: iphone objective-c cocoa-touch uisegmentedcontrol