这可能是一个奇怪的问题,我希望有人以前遇到过。
我使用以下代码向我的 TableView 添加了 SegmentControl:
UIView *headerView = [[UIView alloc] init ];
[headerView addSubview:resultsSegment];
self.tableView.tableHeaderView = headerView;
resultsSegment.frame = CGRectMake(45, 123, 250, 40);
[self.tableView addSubview:resultsSegment];
在这些论坛的帮助下,前三行使 Segment 成为 TableView Header 的一部分,以便它保持在原位以进行滚动。伟大的。
但是,这禁用了单击 SegmentControl 的能力。
添加最后一行使这再次成为可能。
SegmentControl 执行出色的 UNTIL 滚动,然后它变得非常无响应。它不会引发任何错误,并且最终会接受手指的按压,但您必须在它切换之前点击它 5/6 次。
如果有人能对此有所了解,那就太棒了
您需要的任何额外信息我都会很乐意提供!
编辑 - -
视图控制器.h
@interface StdTCPTestViewController : UIViewController <UITableViewDataSource, UITableViewDelegate,UIScrollViewDelegate> {
NSTimer *Timer;
}
@property (nonatomic, strong) NSString *typeOfTest;
@property (nonatomic, strong) NSString *testLocation;
@property (nonatomic, strong) NSString *statusText;
@property (nonatomic, strong) NSString *showResultType;
@property (nonatomic, assign) NSInteger *progressInt;
@property (nonatomic, assign) NSString *testDirection;
@property (strong, nonatomic) IBOutlet UITextView *textView;
@property (strong, nonatomic) IBOutlet UIProgressView *testProgressBar;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, retain) NSArray *ResultTitles;
@property (nonatomic, retain) NSMutableArray *downloadResults;
@property (nonatomic, retain) NSMutableArray *uploadResults;
@property (strong, nonatomic) IBOutlet UISegmentedControl *resultsSegment;
- (IBAction)resultsSwitch:(id)sender;
选择 ViewController.m 的区域
- (void)viewDidLoad
{
[resultsSegment setTitle:@"Download" forSegmentAtIndex:0]; // Sets the title for the 1st segment button
[resultsSegment setTitle:@"Upload" forSegmentAtIndex:1]; // Sets the title for the 2nd segment button
[super viewDidLoad];
// UIView *headerView = [[UIView alloc] init ];
// [headerView addSubview:resultsSegment];
// self.tableView.tableHeaderView = headerView;
resultsSegment.frame = CGRectMake(45, 123, 250, 40);
[self.tableView addSubview:resultsSegment];
[self APISimpleDemo];
self.navigationItem.title = typeOfTest; // Set viewcontroller title to the type of test it is
}
- (IBAction)resultsSwitch:(id)sender {
if([sender selectedSegmentIndex] == 0){
showResultType = @"download";
[self.tableView reloadData];
}
else {
showResultType = @"upload";
[self.tableView reloadData];
}
}
#pragma mark Table Definitions
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // Default is 1 if not implemented
{
return 3;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
{
switch (section) {
case 0:
return @"";
break;
case 1:
return @"";
break;
case 2:
return @"";
break;
default:
return @"Section Count Error";
break;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return 35;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
{
switch (section) {
case 0:
return 10;
break;
case 1:
return 22;
break;
case 2:
return 0;
break;
default:
return 22;
break;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
switch (section) {
case 0:
return 3;
break;
case 1:
return 0;
break;
case 2:
return [ResultTitles count];
break;
default:
return 0;
break;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *serverLoc = [tableView dequeueReusableCellWithIdentifier:@"speedCell"];
switch (indexPath.section) {
case 0:
switch (indexPath.row) {
case 0:
serverLoc.textLabel.text = @"Test location:";
serverLoc.detailTextLabel.text = testLocation;
break;
case 1:
serverLoc.textLabel.text = @"Status:";
serverLoc.detailTextLabel.text = statusText;
break;
case 2:
serverLoc.textLabel.text = @"Progress";
serverLoc.detailTextLabel.text = [NSString stringWithFormat:@"%ld%%", (long)progressInt];
break;
}
break;
case 2:
if ([showResultType isEqual:@"download"]) {
serverLoc.textLabel.text = [self.ResultTitles objectAtIndex:indexPath.row];
serverLoc.detailTextLabel.text = [self.downloadResults objectAtIndex:indexPath.row];
break;
}
else {
serverLoc.textLabel.text = [self.ResultTitles objectAtIndex:indexPath.row];
serverLoc.detailTextLabel.text = [self.uploadResults objectAtIndex:indexPath.row];
break;
}
break;
default:
break;
}
return serverLoc;
}