Apple文档UIViewController说:
如果要实现自己的容器视图控制器,则必须willMoveToParentViewController:在调用removeFromParentViewController方法之前调用子视图控制器的方法,并传入父值nil.
当您的自定义容器调用该addChildViewController:方法时,它会自动调用willMoveToParentViewController视图控制器的:方法作为子项添加,然后再添加它.
如果要实现自己的容器视图控制器,则必须didMoveToParentViewController:在转换到新控制器完成后调用子视图控制器的方法,或者如果没有转换,则在调用addChildViewController:方法后立即调用.
该removeFromParentViewController方法didMoveToParentViewController:在删除子视图后自动调用子视图控制器的方法.
我为什么要调用这些方法?这些方法有什么作用?
ProfileViewController *profile = [[ProfileViewController alloc] init];
profile.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self addChildViewController:profile];
[self.view addSubview:profile.view];
[profile didMoveToParentViewController:self];
Run Code Online (Sandbox Code Playgroud)
即使我删除了最后一行,我的代码也能正常运行.有人可以帮我吗?
提前致谢
我是移动设备上的新手.我正在尝试进行身份验证Amazon Cognito.我首先Credentials Provider使用自定义服务模型登录使用用户名,密码,平台和deviceToken - 然后我获取identityId,endPoint和token.有人告诉我,我需要换我回来的令牌,并刷新我的凭据,以便我经过身份验证才能AWS Cognito和S3.但是所有过程都令人困惑,并且有很多不同的例子.
我创建了一个SignInProvider,扩展了AWSSignInProvider以访问 - (void)登录:(void(^)(id result,NSError*error))completionHanlder; 我在我的登录方法中有我的令牌,端点和identityId.我对完成处理程序做了什么,接下来是什么呢.
@implementation SignInProvider
+(instanceType) sharedInstance{}
- (NSString) identityProviderName{}
- (AWSTask<NSString*>*) token{}
- (BOOL) isLoggedIn{}
- (NSSting*) userName{}
- (void) reloadSession{}
- (void) login: (void (^) (id result, NSError *error)) completionHanlder{
authRequest = [IMPCLDMobileAuthenticationRequest new];
[authRequest setToken:@"930fc1b56d8ca19a84500f9a79af71b65f60331f0242ce4395cdf41186443692"];
[authRequest setPassword:@"pin"];
[authRequest setUsername:@"example@email.co.za"];
[authRequest setPlatform:@"ios"];
serviceClient = [IMPCLDImpressionInternalMicroserviceClient defaultClient];
[[serviceClient mobileAuthenticationPost:authRequest] continueWithBlock:^id(AWSTask *loginTask)
{
//what to do here with my loginTask results (token, endpoint, identityId) …Run Code Online (Sandbox Code Playgroud) authentication objective-c amazon-s3 amazon-web-services ios
在我的iOS应用程序中,我需要接受来自用户的付款.我正在使用UPI.我遵循了UPI提供的以下文件
http://www.npci.org.in/documents/UPI-Linking-Specs-ver-1.1_draft.pdf
我已经创建了文档中所述的深层链接.UIApplication.shared.open用于打开deeplink URL,以便在我的手机中打开任何已安装的PSP(支付服务提供商)应用程序(如PhonePe,BHIM等)
func payButtonClicked() {
guard let urlString = "upi://pay?pa=samplevpa@ybl&pn=Sample Name&am=1&cu=INR".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
else {
return
}
guard let url = URL(string: urlString) else {
return
}
if !UIApplication.shared.canOpenURL(url) {
print("url cannot be opened")
return
}
UIApplication.shared.open(url, options: [:], completionHandler: { (success) in
print(success)
})
}
Run Code Online (Sandbox Code Playgroud)
我已经使用自定义URL方案注册了我的应用程序,并在plist文件中为ApplicationQueriesScheme添加了方案upi
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>SampleApp</string>
</array>
<key>CFBundleURLName</key>
<string>com.company.SampleApp</string>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>upi</string>
</array>
Run Code Online (Sandbox Code Playgroud)
它正在打开PSP应用程序,我可以进行交易.问题是我无法从PSP应用程序中获得响应.方法没有回调UIApplication.shared.open方法.我需要从PSP应用程序返回事务的状态并向用户显示状态.任何帮助赞赏
我正在使用自定义UITableViewCell.当我尝试运行我的代码时,我得到了这个异常堆栈,我无法理解问题的根源:
terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier ((null)) - nib must contain exactly one top level object which must be a UITableViewCell instance'
Run Code Online (Sandbox Code Playgroud)
请注意我没有使用Storyboard.
编辑:
这是我根据断点导致问题的相关代码:
[tableviewSupport registerNib:[UINib nibWithNibName:@"HotelCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:CustomCellCId];
Run Code Online (Sandbox Code Playgroud) 根据定义"宏是一个已经给出名称的代码片段.每当使用该名称时,它将被宏的内容替换".我曾经在我的班级中多次使用的代码中使用宏,基本上是硬编码的字符串.
我的怀疑是:
为了解释我的第二个疑问,我在我的UIView中有一个名为"menuBurger.png"的图像文件.
[self.hamBurgerButton setImage:[UIImage imageNamed:@"menuBurger.png"] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
因此,在这种情况下,有两种方法可以创建宏
情况1 : #define HAMBURGER_BUTTON_IMAGE_NAME @"menuBurger"
案例2: #define HAMBURGER_BUTTON_IMAGE [UIImage imageNamed:@"menuBurger"]
在案例2中我声明宏的方式有什么不对吗?使用宏而不是对象是一个好习惯(如果是2,它返回一个UIImage对象)?
ios ×5
objective-c ×4
amazon-s3 ×1
iphone ×1
macros ×1
payment ×1
swift ×1
swift3 ×1
uitableview ×1
upi ×1