如果我推动视图控制器和/或提供模态视图控制器UINavigationController,我怎样才能找出最顶层的UIViewController?或者在我的情况下,我想知道某个UITableViewController是否是最重要的.
我试过用:
self.navigationController.topViewController == self
Run Code Online (Sandbox Code Playgroud)
......但这不起作用.我猜测它失败了,因为我在它上面呈现模态视图控制器,并且topViewController只跟踪推送了哪些视图UINavigationController(而不是那些以模态方式呈现的视图).
cocoa-touch objective-c uiviewcontroller uinavigationcontroller
嗨,我想用来NSUserDefaults保存数据库中的一些默认值.我能够保存NSUserDefaults(甚至签入NSLog)中的值.现在,我需要重新启动应用程序时app delegate中的值.但是我没有得到任何东西NSUserDefaults.以下是我班上的代码,我将值保存在NSUserDefaults:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:appDel.dictProfile forKey:@"dict"];
NSLog(@"%@",[prefs valueForKey:@"dict"]);
Run Code Online (Sandbox Code Playgroud)
以下是来自App Delegagte的代码:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSLog(@"%@",[prefs valueForKey:@"dict"]);
Run Code Online (Sandbox Code Playgroud)
上面的代码总是返回null.有人可以帮帮我吗?
根据我的知识:
PUT - 用其整个表示更新对象(替换)PATCH - 仅使用给定字段更新对象(更新)我正在使用Spring来实现一个非常简单的HTTP服务器.当用户想要更新他的数据时,他需要将HTTP PATCH发送到某个端点(比方说:) api/user.他的请求体被映射到DTO via @RequestBody,如下所示:
class PatchUserRequest {
@Email
@Length(min = 5, max = 50)
var email: String? = null
@Length(max = 100)
var name: String? = null
...
}
Run Code Online (Sandbox Code Playgroud)
然后我使用这个类的对象来更新(补丁)用户对象:
fun patchWithRequest(userRequest: PatchUserRequest) {
if (!userRequest.email.isNullOrEmpty()) {
email = userRequest.email!!
}
if (!userRequest.name.isNullOrEmpty()) {
name = userRequest.name
}
...
}
Run Code Online (Sandbox Code Playgroud)
我的疑问是:如果客户(例如网络应用程序)想清除房产怎么办?我会忽略这样的改变.
我怎么知道,如果用户想要清除一个属性(他故意将我命名为null)或者他只是不想改变它?在两种情况下,它在我的对象中都是null.
我可以在这里看到两个选项:
@Valid现在用.如何妥善处理此类案件,与REST和所有良好做法保持一致?
编辑:
可以说不PATCH应该在这样的例子中使用,我应该PUT用来更新我的用户.但是模型更改怎么样(例如添加新属性)?每次用户更改后,我都必须对我的API(或单独的用户端点)进行版本控制.例如,我将有api/v1/user终点,它接受PUT一个老请求主体和api/v2/user …
我在这样的方法中附加一个UISwipeGestureRecognizera :UITableViewCellcellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
gesture.direction = UISwipeGestureRecognizerDirectionRight;
[cell.contentView addGestureRecognizer:gesture];
[gesture release];
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
但是,该didSwipe方法在成功滑动时始终被调用两次.我最初认为这是因为手势开始和结束,但如果我注销gestureRecognizer本身,它们都处于"结束"状态:
-(void)didSwipe:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"did swipe called %@", gestureRecognizer);
}
Run Code Online (Sandbox Code Playgroud)
安慰:
2011-01-05 12:57:43.478 App[20752:207] did swipe called <UISwipeGestureRecognizer: 0x5982fa0; state = Ended; view = <UITableViewCellContentView …Run Code Online (Sandbox Code Playgroud) (这既是问题又是答案,因为需要花费大量时间才能找到真正的答案.)
症状:viewWillAppear,viewDidAppear没有被称为在我的UIViewController.
原因:嵌入一个UINavigationController或UITabBarController(我的情况)以UIViewController某种方式中断调用这些方法.
解决方案:在UIViewController包含上述UINavigationController/的手动调用它们UITabBarController.
例如(假设projectNavigationController是你的UINavigationController):
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[projectNavigationController viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[projectNavigationController viewWillDisappear:animated];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[projectNavigationController viewDidAppear:animated];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[projectNavigationController viewDidDisappear:animated];
}
在我的情况下,我有一个内部UITabBarController,我相应地调用方法,所有都解决了.
(对解决方案的归因:http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/)
我正在尝试发布ClickOnce应用程序并在本地测试它.我想提供安装链接,所以我需要用IP地址更新位置,除非我无法安装它(因为它localhost被翻译成计算机名并且无法访问).问题是,IIS我可以通过localhost在地址中使用来访问我的页面.
http://localhost:9995/publish/Publish.htm <-- working
http://192.168.1.104:9995/publish/Publish.htm <-- not working (my IP address)
http://my_pc_name:9995/publish/Publish.htm <-- not working
http://127.0.0.1:9995/publish/Publish.htm <-- even that is not working
Run Code Online (Sandbox Code Playgroud)
我正在使用Windows 7和Visual Studio 2012使用IIS Express 8.0,但我尝试了相同的Visual Studio 2010,它ASP.NET server仍然失败了.我关闭了防火墙.
你有什么想法可能有什么不对吗?
我有一个参考NSAttributedString,我想更改属性字符串的文本.
我想我必须创建一个新的NSAttributedString并使用这个新字符串更新引用.但是,当我这样做时,我失去了之前字符串的归属.
NSAttributedString *newString = [[NSAttributedString alloc] initWithString:text];
[self setAttributedText:newString];
Run Code Online (Sandbox Code Playgroud)
我参考了旧的属性字符串self.attributedText.如何保留新字符串中的先前属性?
我需要拥有方法的类的名称,如NSString.示例:a中有一个-fooBar方法SomeClass,该-fooBar方法运行一些代码.这段代码必须打印出哪个类"拥有"它,我的意思是:该方法属于哪个类.所以我不能在a中硬输入类名,NSString因为我需要它来进行调试,动态确定类的名称.难以解释.任何的想法?
我试图产生类似于新雅虎天气应用程序中的效果.基本上,每个页面UIPageViewController都有一个背景图像,当滚动浏览页面视图时,图像的位置只滚动大约一半的速度.我该怎么办?我以为我可以使用某种委托方法UIPageViewController获取当前偏移量,然后像这样更新图像.唯一的问题是我无论如何都无法判断是否UIPageViewController正在滚动!有没有办法呢?谢谢!
在安全性方面,将localhostATS 添加到NSExceptionDomains开发用途是否安全?Info.plist在每次提交之前从文件中删除这些行并不是很方便(并且很容易忘记).
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
此外,Apple可以拒绝该应用程序吗?
iphone ×5
objective-c ×4
ios ×3
cocoa-touch ×2
asp.net ×1
clickonce ×1
https ×1
iis ×1
ip ×1
ipad ×1
kotlin ×1
localhost ×1
patch ×1
rest ×1
spring ×1
spring-boot ×1
uiimage ×1
uikit ×1
uiscrollview ×1
uitableview ×1