我创建了一个空白的iPhone应用程序项目,并希望在应用程序启动期间显示全屏广告.
我尝试按照以下准则安装广告:https://github.com/mopub/mopub-ios-sdk/wiki/Interstitial-Integration-For-iOS
这就是我最后所做的:


实际上所有代码都只是从上一个链接复制而来.
但是,应用程序运行时会显示错误:
应用程序窗口应在应用程序启动结束时具有根视图控制器
我认为这个错误可能与loadView方法有关,因为如果删除loadView方法,错误就会消失.
事实上,这个错误似乎很常见,因为它可以在互联网上轻松搜索,但我不知道loadView是如何与它相关的,以及如何在我的情况下解决它.
有解决方案吗 非常感谢.
我想显示一个加载视图,即一个不确定的进度条,直到我使用从Firebase获取的数据加载我的回收器视图.我需要知道在Recycler View加载数据后会立即触发的事件.
我扩展了这个类并用作适配器
我的扩展课程是
public class TrendingRecycler extends FirebaseRecyclerAdapter
<TrendingRecycler.ViewHolder, DataStuff> {
public static class ViewHolder extends RecyclerView.ViewHolder {
TextView Data;
public ViewHolder(View view) {
super(view);
Data= (TextView) view.findViewById(R.id.text_card_trending);
}
}
public TrendingRecycler(Query query, Class<DataStuff> itemClass) {
super(query, itemClass);
}
@Override public TrendingRecycler.ViewHolder
onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.trending_card_view, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(TrendingRecycler.ViewHolder holder,
int position) {
final DataStuff item = getItem(position);
holder.Data.setText(item.Data);
final Context context =holder.itemView.getContext();
holder.itemView.setOnClickListener(new View.OnClickListener() …Run Code Online (Sandbox Code Playgroud) 任何人都可以解释为什么在使用loadView时不会调用viewDidLoad?我的理解是viewDidLoad应该仍然被调用.
- (void)loadView
{
CGRect currentFrame = [[UIScreen mainScreen] applicationFrame];
UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(currentFrame.origin.x, currentFrame.origin.y, currentFrame.size.width, currentFrame.size.height)];
myView.backgroundColor = [UIColor redColor];
self.view = myView;
[myView release];
[super loadView];
}
- (void)viewDidLoad {
//this never happens
NSLog(@"VIEW DID LOAD!");
[super viewDidLoad];
}
Run Code Online (Sandbox Code Playgroud) 如果我覆盖loadView方法,则会调用loadView是否存在nib文件.如果我不覆盖loadView并且有一个nib文件,它会被调用吗?
我有没有xib的UIViewController,我正在使用loadView来构建我创建并添加两个滚动视图的UI.问题是,当旋转发生时,主视图框架大小不会改变.我的意思是,我在loadView中为主视图设置初始帧大小(纵向模式:帧大小宽度= 320,高度= 480).在旋转到横向方向后,视图主框架尺寸不会改变,并且与纵向模式相同.这是我的loadView:
-(void)loadView{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height)] autorelease];
self.view.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
self.scrollView1 = [[[UIScrollView alloc] init] autorelease];
self.scrollView1.frame = CGRectMake...
[self.view addSubview:self.scrollView1];
self.scrollView2 = [[[UIScrollView alloc] init] autorelease];
self.scrollView2.frame = CGRectMake...
[self.view addSubview:self.scrollView2];
Run Code Online (Sandbox Code Playgroud)
我还为视图设置了autoresizingMask以扩展或缩小以适应屏幕.但是在调试控制台时我得到相同的宽度和高度值.我需要获得一个新的大小,因为我需要在旋转发生时重新定位我的两个scrollViews,例如缩小高度并将scrollViews上的宽度扩展到旋转到横向模式.我可以在shouldRotate中手动完成,只是好奇它应该如何以正确的方式完成.
请告诉我init和loadView方法被调用的时间.据我所知,初始化视图时,init方法只被调用一次,并且loadView在加载视图的任何时候调用它.因此,即使您在视图堆栈中推送新视图然后弹出它,也loadView应该调用加速视图.但是当我在调试模式下运行我的代码时,无论我加载相同的屏幕多少次,这两种方法都被调用一次.如果我错过了什么,请告诉我.
I have a common view used when the user opens the app (VC1). With a tab bar controller, I load another view (VC2) that can be used to update data visible in the previous one. When I go back on VC1 (which is stack), it does not reload with updated data.
I have tried to call the viewDidLoad in the viewWillAppear like so...
override func viewWillAppear(_ animated: Bool) {
viewDidLoad()
}
Run Code Online (Sandbox Code Playgroud)
It works, but it loads over the VC1 still …
我正在学习为iPhone开发(以编程方式,我不喜欢IB).我只使用IB作为帧的东西,所以我在IB中设计但只用它来检查每个控件的帧.我非常困惑的是UIView的框架.首先,如果你没有在视图控制器中实现loadView,它会自动创建一个空的UIView(我注意到它的黑色)并将其分配给self.view,对吗?框架怎么样?它会自动找出框架应该是什么吗?我的意思是,它需要有所不同,具体取决于是否有状态栏,是否有标签栏,工具栏,方向.在我的标签栏应用程序中,似乎无论我设置的uiview框架是什么,它看起来仍然很好.而且,UIView的框架似乎在IB中搞砸了.就像UIView占据整个窗口(状态栏除外)的y值是0,当它应该是20时,因为状态栏占据前20个像素.在IB中,标签栏控制器中的视图的值为411,即使它始于状态栏下方.每当我NSLog一帧(四个数字,view.frame.origin.x,view.frame ......等),x,y,宽度和高度总是为0 ..可以理解它的人请解释它我?谢谢!!
好的,这很奇怪......这个:
CGRect test = CGRectMake(0, 20, 320, 460);
NSLog(@"%d %d %d %d", test.origin.x, test.origin.y, CGRectGetWidth(test), CGRectGetHeight(test));
Run Code Online (Sandbox Code Playgroud)
给出输出:
0 0 0 1077149696
Run Code Online (Sandbox Code Playgroud)
??? 那是什么?
两个objective-c方法, - (void)viewDidLoad和 - (void)loadView是在执行程序时调用的方法,但它们之间有什么不同?
我需要一个没有xib的视图控制器.应该有一个完全填充到视图的webview.为此,我已将以下代码添加到loadView方法.
- (void)loadView {
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIView *view = [[UIView alloc] initWithFrame:applicationFrame];
view.translatesAutoresizingMaskIntoConstraints = NO;
[view setBackgroundColor:[UIColor greenColor]];
[self setView:view];
// //create webview
self.webview = [[UIWebView alloc] initWithFrame:CGRectZero];
self.webview.translatesAutoresizingMaskIntoConstraints = NO;
[view addSubview:self.webview];
[self.webview setBackgroundColor:[UIColor orangeColor]];
[self.webview setDelegate:self];
NSDictionary *viewBindings = NSDictionaryOfVariableBindings(view,_webview);
// //add constraints
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_webview]|" options:0 metrics:nil views:viewBindings]];
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_webview]|" options:0 metrics:nil views:viewBindings]];
}
Run Code Online (Sandbox Code Playgroud)
但这会将整个视图变为黑色.如果我执行[view addConstraints:...方法调用它显示绿色视图.我的代码出了什么问题?
为什么每次加载此视图后,以下应用程序都会崩溃?
-(void)loadView {
UIButton *chooseSubjectButton = [[UIButton buttonWithType:UIButtonTypeDetailDisclosure] retain];
[chooseSubjectButton addTarget:self action:@selector(chooseSubject) forControlEvents:UIControlEventTouchUpInside ];
chooseSubjectButton.frame = CGRectMake(15.0f, 205.0f, 296.0f, 51.0f);
[self.view addSubview:chooseSubjectButton];
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
谢谢!