【发布时间】:2012-04-25 08:47:36
【问题描述】:
我有一个带有多个分段控件的 iPad 应用程序,包括一个带有两个控件的视图。
在该视图中,所有内容都显示在 sim 中,包括正常和视网膜。但是,在设备中,只有一个显示。
以下是设备上未显示的代码。我已经检查过,构成控件的所有图像都复制到了捆绑资源中。我试过移除、清洁等。没有乐趣。我一定是遗漏了一些东西(希望很简单)..
UISegmentedControl *controls = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
nil]];
CGRect frame = CGRectMake(35, 70, 700, 35);
controls.frame = frame;
}
[controls addTarget:self action:@selector(drawSegmentAction:) forControlEvents:UIControlEventValueChanged];
controls.segmentedControlStyle = UISegmentedControlStyleBar;
controls.momentary = YES;
controls.tintColor = [UIColor grayColor];
[self.view addSubview:controls];
}
作为参考,同一视图中的这段代码确实有效:
作为参考,这个控制代码确实有效:
-(void) buildColorBar {
//NSLog(@"%s", __FUNCTION__);
UISegmentedControl *colorControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects: [UIImage imageNamed:@"White.png"],
[UIImage imageNamed:@"Red.png"],
[UIImage imageNamed:@"Yellow.png"],
[UIImage imageNamed:@"Green.png"],
[UIImage imageNamed:@"Blue.png"],
[UIImage imageNamed:@"Purple.png"],
[UIImage imageNamed:@"Black.png"],
nil]];
NSLog(@"Portrait");
CGRect frame = CGRectMake(35, 950, 700, 35);
colorControl.frame = frame;
// When the user chooses a color, the method changeBrushColor: is called.
[colorControl addTarget:self action:@selector(changeBrushColor:) forControlEvents:UIControlEventValueChanged];
colorControl.segmentedControlStyle = UISegmentedControlStyleBar;
// Make sure the color of the color complements the black background
colorControl.tintColor = [UIColor grayColor];
// Add the control to the window
[self.view addSubview:colorControl];
}
是否有禁止在一个视图中使用两个分段控件的规则?
【问题讨论】:
-
明显的问题...您是否放入了 NSLog 并确保代码正在运行?只是制作一个带有一些随机背景颜色的 UIView,看看它是否是创建控件的问题,或者它是否更像是一个基本的布局/添加子视图问题?
-
是的,代码已记录并正在运行。我可以看到按钮也可以工作(在 sim 上)。奇怪...
标签: xcode device uisegmentedcontrol