我有以下代码:
func registerNotification(name:String, selector:Selector)
{
NSNotificationCenter.defaultCenter().addObserver(self, selector: selector, name: name, object: nil)
}
func registerKeyboardNotifications()
{
let isInPopover = navigationController?.popoverPresentationController != nil
let ignore = isInPopover && DEVICE_IS_IPAD
if !ignore {
registerNotification(UIKeyboardWillShowNotification, selector: Selector("keyboardWillShow:"))
registerNotification(UIKeyboardWillHideNotification, selector: Selector("keyboardWillHide:"))
}
}
Run Code Online (Sandbox Code Playgroud)
在延伸UIViewController.许多viewcontroller重用此代码来注册键盘通知.但是使用Swift 2.2会产生警告.我喜欢新的#selector语法,但不知道在这种情况下如何实现它.
我认为正确的解决方案是制定协议并UIViewController仅针对符合该协议的实例进行扩展.我的代码到目前为止:
@objc protocol KeyboardNotificationDelegate
{
func keyboardWillShow(notification: NSNotification)
func keyboardWillHide(notification: NSNotification)
}
extension UIViewController where Self: KeyboardNotificationDelegate
{
func registerKeyboardNotifications()
{
let isInPopover = navigationController?.popoverPresentationController != nil
let ignore = isInPopover && DEVICE_IS_IPAD …Run Code Online (Sandbox Code Playgroud) 为什么它会缓存响应.它返回先前获取的响应.它甚至可以在关闭网络连接时工作.重置iOS模拟器似乎也不起作用.提出请求,然后再次使用Internet脱机工作(缓存).
public let urlSession: NSURLSession
public init()
{
// ...
var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.requestCachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData
urlSession = NSURLSession(configuration: configuration)
}
func makeRequest(path: String, httpMethod:String, body:String?, baseUrl: String?, headers:[String:String]=[:], callback: JsonRequestCallback)
{
let urlString = (baseUrl ?? customOAuth2Manager.API_URL) + path
let url = NSURL(string: urlString)
let request = oauthInstance.request(forURL: url!)
request.HTTPMethod = httpMethod
self.customOAuth2Manager.setupRequest(request)
for (key, value) in headers {
request.setValue(value, forHTTPHeaderField:key)
}
if let body = body where body != "" {
let postData = (body as NSString).dataUsingEncoding(NSUTF8StringEncoding) …Run Code Online (Sandbox Code Playgroud) caching nsurlcache nsurlsession nsurlsessionconfiguration swift
我正在使用 Firebase 函数构建一个解析 CSV 文件的 API。
当我尝试使用 csv-parse/sync 而不是 csv-parse 时,部署到 Firebase Functions 失败并出现以下错误:
Error: Error parsing triggers: Cannot find module 'csv-parse/sync''
Require stack:
- /Users/xxx/Programming/xxx/Firebase Functions/xxx/functions/lib/index.js
- /usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/triggerParser.js
Try running "npm install" in your functions directory before deploying.
Run Code Online (Sandbox Code Playgroud)
我已经使用以下方式导入:
import { parse } from 'csv-parse/sync';
然后在这样的代码中使用:
interface EventData {
update: string;
id: string;
title: string;
description: string;
category: string;
ages: string;
place: string;
placeCoordinate: string;
startDate: string;
startTime: string;
length: string;
url: string;
arrName: string;
}
let events: Array<EventData> …Run Code Online (Sandbox Code Playgroud) 简单的问题,但似乎很难找到.
我正在构建Android和iOS游戏.我想提取应用程序的版本(即"2.0.1")(如果App Store/Google Play上有更新的版本,则显示弹出窗口).
有人知道如何以编程方式执行此操作吗?
我在将Google AnalyticsSDK集成到iOS项目时遇到了很多麻烦.我正在使用XCode 7并以iOS 7为目标.使用Swift 2.0.但是我可以让样本正常工作(尽管不转换为Swift 2.0).
我已尝试通过CocoaPods安装并手动复制文件:
https://developers.google.com/analytics/devguides/collection/ios/v3/sdk-download
通过CocoaPods安装时,我尝试了两种方法
pod 'Google/Analytics'
Run Code Online (Sandbox Code Playgroud)
,
pod 'GoogleAnalytics'
Run Code Online (Sandbox Code Playgroud)
和
pod 'Google/Analytics', '~> 1.0.0'
Run Code Online (Sandbox Code Playgroud)
无论哪种情况,XCode构建都会失败并出现错误
BridgingHeader.h:2:9: 'Google/Analytics.h' file not found
Failed to import bridging header '/Users/jonas.andersson/Projects/MyAppName/MyAppName/Supporting files/BridgingHeader.h'
Run Code Online (Sandbox Code Playgroud)
这个在行:
#import <Google/Analytics.h>
Run Code Online (Sandbox Code Playgroud)
我也尝试过添加
$(SRCROOT)/Pods/GoogleAnalytics
Run Code Online (Sandbox Code Playgroud)
添加到AppDelegate时找不到Google/Analytics.h文件中的其他建议
更新
使用pod 'GoogleAnalytics'然后#import <Google/Analytics.h>更好地工作.但是,我收到以下错误:
Use of unresolved identifier 'GGLContext'
Run Code Online (Sandbox Code Playgroud)
当我根据Google文档尝试设置GA时:
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
Run Code Online (Sandbox Code Playgroud) 我刚刚下载了适用于Mac OS X的"Mono for Android"/ MonoDevelop 3.1.1的试用版.我正在尝试使用XDocument解析一些XML.但我似乎无法找到我需要的导入:
using System.Xml.Linq;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
The type or namespace name 'Linq' does not exist in the namespace 'System.xml'. Are you missing an assembly reference?
Run Code Online (Sandbox Code Playgroud)
在解决方案资源管理器中的引用下打开System.Xml引用显示其中没有Linq:
System.Xml
- References
- mscorlib
- System
- System.Xml
- System.Xml.Schema
- System.Xml.Serialization
- System.Xml.XPath
- System.Xml.Xsl
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
编辑:更多信息:
运行时:单声道2.10.9(tarball)
适用于Android的单声道:4.4.55(评估)
Monotouch:Xamarin.Mac:未安装
操作系统:Mac OS X 10.8.2
的System.Xml:
问题总结:当我在有很多细胞经常死机UITableView动画的高度时UITableViewCell从UITextView编辑它的文本.使用iOS 8自定义单元格.
长问题:我已经成功实现了所以我可以动态地使用iOS 8自定义单元格将文本输入到单元格UITextView中并更改单元格高度而不会失去焦点(firstReponder).但是,如果tableView太大(行太多),它会崩溃.这是我的堆栈跟踪:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b3b3d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010b9cbdeb objc_exception_throw + 48
2 CoreFoundation 0x000000010b274cc5 -[__NSArrayM insertObject:atIndex:] + 901
3 UIKit 0x0000000108b05439 __46-[UITableView _updateWithItems:updateSupport:]_block_invoke1029 + 180
4 UIKit 0x0000000108a7e838 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 582
5 UIKit 0x0000000108a7ec6d +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 105
6 UIKit 0x0000000108b05048 -[UITableView _updateWithItems:updateSupport:] + 4590 …Run Code Online (Sandbox Code Playgroud) 我正在使用工具栏创建一个searchview onCreateOptionsMenu,但无法获得X最初为白色的清除按钮.开始输入字母时变为白色.清理后它也会保持白色.
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.responsible_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); //TODO: May not be needed?
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()
{
@Override
public boolean onQueryTextSubmit(String query)
{
mAdapter.updateUIWithFilter(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText)
{
mAdapter.updateUIWithFilter(newText);
return false;
}
});
// Does not work! Still not white.
ImageView searchClose = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
searchClose.setColorFilter(Color.argb(255, 255, 255, 255));
searchClose.setAlpha(255);
return true;
}
Run Code Online (Sandbox Code Playgroud)
responsible_menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" …Run Code Online (Sandbox Code Playgroud) 我正在开发一个在后台作为服务运行的网络监视器应用程序.屏幕打开或关闭时是否可以收到通知/电话?
它通过使用以下代码存在于Android中:
private void registerScreenOnOffReceiver()
{
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(screenOnOffReceiver, filter);
}
Run Code Online (Sandbox Code Playgroud)
然后在打开/关闭屏幕时调用screenOnOffReceiver.iOS有类似的解决方案吗?
编辑: 到目前为止我发现的最好的是UIApplicationProtectedDataWillBecomeUnavailable(检测iPhone屏幕是否打开/关闭),但它要求用户在设备上启用数据保护(密码保护).
我想简化在UITableViewCell子类中调用"setup"方法的过程.但是,并非所有设置方法都相同,但它们的参数继承自相同类型.是否可以使用泛型或协议不必每次都抛出参数?
首先,我是一个像这样的cellForRow方法:
class DataSource<V : UIViewController, T: TableViewCellData, VM: ViewModel> : NSObject, UITableViewDataSource, UITableViewDelegate {
var dataCollection: TableViewDataCollection<T>!
var viewModel: VM!
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellData = dataCollection.object(for: indexPath)
let cell = tableView.dequeueReusableCell(withIdentifier: cellData.identifier(), for: indexPath)
if let setupableCell = cell as? CellDataSetupable {
setupableCell.setup(with: cellData, viewModel: viewModel)
}
return cell
}
}
protocol CellDataSetupable : class {
func setup(with cellData: TableViewCellData, viewModel: ViewModel)
}
Run Code Online (Sandbox Code Playgroud)
我使用cellData和viewModel设置单元格.
在我的(很多)自定义UITableViewCell子类中:
extension BlurbTableViewCell : CellDataSetupable {
func …Run Code Online (Sandbox Code Playgroud) ios ×4
swift ×3
c# ×2
android ×1
broadcast ×1
caching ×1
cocoapods ×1
firebase-cli ×1
generics ×1
ios9 ×1
jailbreak ×1
linq ×1
mono ×1
monodevelop ×1
node.js ×1
nsurlcache ×1
nsurlsession ×1
objective-c ×1
searchview ×1
swift2 ×1
swift2.2 ×1
typescript ×1
uitableview ×1
xcode ×1
xcode7 ×1