【发布时间】:2012-02-22 00:33:56
【问题描述】:
在我的应用程序的一个用户界面中,我希望我的应用程序显示一个滚动视图(滚动页面的计数在运行时动态设置)。但我想将 UIWebView 和 UIView 元素添加到同一个数组中,这样当我滚动时,我将能够同时显示 UIWebView(比如说网页)和其他一些视图?
编辑
我收到了这个看起来完全正常但不起作用的答案(或者我不能) 这是代码: NSArray *myArray; // 这里用一堆 UIWebView 和 UIView 对象填充数组
for (id theObject in myArray)
{
if ([theObject isKindOfClass:[UIWebView class]]) {
// do stuff
}
else if ([theObject isKindOfClass:[UIView class]]) {
// do other stuff
}
}
有人可以帮忙吗?我需要创建一个可滚动的视图数组(如 iPhone 的主页),但第一页(意思是视图)必须是 UIWebView 的成员(其他是 UIView)
下面是我所有的代码(我不想在这里做任何事情:)
CGRect frame;
[webView initWithFrame:frame];
NSArray *colors = [NSArray arrayWithObjects:webView, [UIColor blackColor],[UIColor blackColor], nil];
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [colors objectAtIndex:i];
[subview setTag:i];
if([subview tag]==2){
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(70.0f, 600.0f, 250.0f, 60);
[button setTitle:@"Read Messages" forState:UIControlStateNormal];
for(NSDictionary* buttonData in butDat) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
NSString* buttonTitle = [buttonData objectForKey:@"name"];
NSString* buttonID=[buttonData objectForKey:@"order_number"];
[button setTitle:buttonTitle forState:UIControlStateNormal];
[button setTag:[buttonID intValue]];
button.titleLabel.font=[UIFont systemFontOfSize:28];
CGFloat yPosition = 60.0f;
const CGFloat buttonHeight = 85.0f;
if (button.tag==1) {
button.frame = CGRectMake(70.0f, yPosition, 250.0f, buttonHeight);
//[ma.view addSubview:button];
}
if (button.tag==2) {
button.frame = CGRectMake(440.0f, yPosition, 250.0f, buttonHeight);
//[ma.view addSubview:button];
}
if (button.tag==3) {
button.frame = CGRectMake(70.0f, 200.0f, 250.0f, buttonHeight);
//[ma.view addSubview:button];
}
if (button.tag==4) {
button.frame = CGRectMake(440.0f, 200.0f, 250.0f, buttonHeight);
//[menu_2.view addSubview:button];//****
}
if (button.tag==5) {
button.frame = CGRectMake(70.0f, 335.0f, 250.0f, buttonHeight);
//[menu_2.view addSubview:button];//****
}
if (button.tag==6) {
button.frame = CGRectMake(440.0f, 335.0f, 250.0f, buttonHeight);
//[menu_2.view addSubview:button];//****
}
[button addTarget:self action:@selector(secondAct:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
}
//
[button addTarget:self action:@selector(readM:) forControlEvents:UIControlEventTouchUpInside];
// [scrollView addSubview:button];
[self.view addSubview:button];
// [self.scrollView addSubview:button];
}
[self.scrollView addSubview:subview];
【问题讨论】:
标签: iphone uiwebview uiscrollview uipagecontrol