我正在运行 5.0.1 版 (5A2053),每次单击播放按钮在 iPad 上运行我的应用程序时,都会打开右侧面板。
它对我没有任何价值,在关闭它约 200 次后,我很感兴趣是否有一些 Xcode 5.0.1 设置来防止在设备上运行应用程序时显示右侧面板。
抱歉,如果这个问题不是非常面向编程,但随着时间的推移,它肯定会增加一些挫折感。
使用NSTimer之后,将永远不会调用类deinit方法。该类是用Swift编写的,我在“ init”处调用计时器,如下所示:
init(eventsDistributor : EventsDistributor, orderSide : ORDER_SIDE, stockViewModel : StockViewModel, orderType : ORDER_TYPE_ENUM, orderPrice : NSNumber) {
self.eventsDistributor = eventsDistributor
self.orderSide = orderSide
self.stockViewModel = stockViewModel
self.orderType = orderType
self.orderPrice = orderPrice
super.init()
_events()
loadPreOrderDetails()
//Here I call the Timer:
var reloadTimer = NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: "loadSecurityTradeInfo", userInfo: nil, repeats: true)
reloadTimer.fire()
}
Run Code Online (Sandbox Code Playgroud)
我也尝试将NSTimer用作局部变量,但在该处没有成功...有人遇到此问题吗?我可以在Swift中使用一个不会导致不取消分配类的计时器吗?谢谢
使用该willDisplayCell方法,我得到了最后一个可见单元格的索引:
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
indexVisibleCell = [indexPath indexAtPosition:[indexPath length] - 1];
}
Run Code Online (Sandbox Code Playgroud)
这里indexVisibleCell是一个NSUInteger是在类的接口中声明。我的问题是,当用户点击向右或向左按钮时,我只希望移动一个单元格。我已经为此目的应用了此代码:
- (IBAction)rightButton:(id)sender {
NSUInteger indexOfScrolledCell;
indexOfScrolledCell = indexVisibleCell;
if (indexVisibleCell < 9) {
NSIndexPath *path = [NSIndexPath indexPathForRow:indexOfScrolledCell+1 inSection:0];
[self.obj_CollectionView1 scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
因为我一次显示3个单元格。通过使用rightButton动作方法,它一次移动3个单元格,而不是一个。请帮助我弄清楚如何一次滚动一个单元格。
我尝试在我的应用程序委托中创建弹出警报消息,但它根本没有显示。程序是用Swift 4编写的。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let alert = UIAlertController(title: "title", message: "message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud) 我在 iOS 13 上遇到一个问题,当UIBarButton我切换 iOS 主题时图标不会改变。
我为深色和浅色主题创建了两组图像,并将它们添加到 xcassets 中,如下图所示。
当我更改主题时,该主题的图像不会反映,但如果我点击它,它就会改变。
步骤和屏幕录制。
我尝试创建新的栏按钮并分配相同的图标而无需继续。当主题改变时,图标也不会改变,当我点击它时,图标也不会改变。
下面是屏幕录制。
可能是什么原因?
我正在努力在我的应用程序中实现插页式广告,但对 AdMob 提供的文档和新的 SwiftUI 应用程序结构遇到了一些困惑。
这是app.swift文件,显示我已经实现了 GoogleMobileAds 并在didFinishLaunchingWithOptions方法中启动了它。
import SwiftUI
import GoogleMobileAds
@main
struct AdamsCalcApp: App {
var calculator = Calculator()
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView().environmentObject(calculator)
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Setup Google AdMob instance
GADMobileAds.sharedInstance().start(completionHandler: nil)
return true
}
}
Run Code Online (Sandbox Code Playgroud)
在我的ContentView.swift文件中,我创建了间隙变量,如下所示:
@State var interstitial: GADInterstitialAd?
Run Code Online (Sandbox Code Playgroud)
然后,在视图的主堆栈上,我调用onAppear(perform:)加载广告:
.onAppear(perform: …Run Code Online (Sandbox Code Playgroud) AppDelegate在我的 Swift iOS 应用程序中,我在内部异步设置了初始视图控制器didFinishLaunchingWithOptions。现在我添加了一个通用链接,这样如果您转到手机上的相应 URL,它将自动打开应用程序中的正确页面(在本例中,它是一个密码重置 URL,如果正确,将打开密码重置表单在应用程序内)。
我正在处理application(_:continue:restorationHandler:)我continueUserActivity的AppDelegate.
如果应用程序已经在运行,则它可以工作,但否则链接处理会在我的应用程序完成设置初始视图控制器之前发生,并且didFinishLaunchingWithOptions返回时深层链接的视图控制器将被关闭。
在呈现视图控制器之前,如何确保应用程序已完成设置continueUserActivity?didFinishLaunching在设置视图控制器之前,我不能/不应该阻止返回,因此该方法在呈现初始视图控制器之前返回。
我知道我可以检查内部的用户活动字典,didFinishLaunchingWithOptions但continueUserActivity仍然被调用(如果仅在应用程序运行时调用它会简单得多,就像didReceiveRemoteNotification工作原理一样)。是否有一个条件要检查此方法内部以将链接处理推迟到didFinishLaunching?
一些简化的UIApplicationDelegate代码有助于解释:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
doSomeAsyncSetup(
completion: {
presentSomeViewController()
}
)
return true
}
func application(_: UIApplication, continue userActivity: NSUserActivity, restorationHandler _: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let …Run Code Online (Sandbox Code Playgroud) 当我的iOS应用程序打开时,它会显示本地蓝牙设备列表,然后单击一个.如果蓝牙已关闭,则会出现一个系统警报,要求您打开它(使用按钮转到"设置",另一个按钮单击"确定"); 如果您打开设置,它不会再次扫描,您必须
如何在蓝牙打开时注册一种运行方法的通知?
我看到了一些关于"BluetoothAvailabilityChangedNotification"的内容,但是当打开/关闭蓝牙时似乎没有调用它.
这是我试过的代码:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(bluetoothAvailabilityChanged:)
name:@"BluetoothAvailabilityChangedNotification"
object:nil];
Run Code Online (Sandbox Code Playgroud)
...
-(void) bluetoothAvailabilityChanged: (NSNotification*) notification {
NSLog(@"Bluetooth changed %@",notification.description);
}
Run Code Online (Sandbox Code Playgroud) 我有下面的代码显示了location_id反社会犯罪的总数,但我想location_name从另一个名为" location_dim输出"的表中获取.我试图找到一种方法,UNION但无法让它工作.有任何想法吗?
SELECT fk5_location_id , COUNT(fk3_crime_id) as TOTAL_ANTISOCIAL_CRIMES
from CRIME_FACT
WHERE fk1_time_id = 3 AND fk3_crime_id = 1
GROUP BY fk5_location_id;
Run Code Online (Sandbox Code Playgroud) Parse文档提供了使用Swift的查询示例,它们显示了访问内置字段(如objectId或count)的示例,但是如何访问对象的其中一列呢?
var query = PFQuery(className: "MyObject")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if !(error != nil) {
for object in objects {
println(object["name"])
}
else {
println("%@", error)
}
}
Run Code Online (Sandbox Code Playgroud)
获取错误"AnyObject"不可转换为字符串.
object.objectForKey("name")
Run Code Online (Sandbox Code Playgroud)
还给出一个错误:"无法找到接受所提供参数的'objectForKey'的重载"
现在我也试过"作为PFObject"或类似的东西,但它也导致错误加上Parse的文档没有显示出类似的东西."类型'[AnyObject]'不能隐含地向下转换为'PFObject';你是不是想用'as'强制向下转换?"
然后我应用修复,新错误是"类型'PFObject'不符合协议'SequenceType'
试图在循环内向下倾斜
let pf = object as PFObject
Run Code Online (Sandbox Code Playgroud)
但这似乎没有帮助,因为当我这样做
let name = pf["name"]
Run Code Online (Sandbox Code Playgroud)
我得到''AnyObject'不能转换为'String'"
谢谢你的帮助.我确定我错过了一些明显的东西,因为我还没有找到任何东西;
我有UICollectionView2个部分.我想在用户点击它时选择单元格.
每次用户点击单元格时,我的代码都会正确运行,单元格会变小,并且会在其中显示复选标记(imageView我将其添加为单元格的子视图).问题是如果我在第一部分点击一个单元格,它会在第二部分中选择另一个单元格.这很奇怪,因为我使用了indexPath.
这是我的代码:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// handle tap events
let cell = collectionView.cellForItemAtIndexPath(indexPath)
let centerCell = cell?.center
if cell!.frame.size.width == cellWidth {
cell?.frame.size.width = (cell?.frame.size.width)!/1.12
cell?.frame.size.height = (cell?.frame.size.height)!/1.12
cell?.center = centerCell!
let imageView = UIImageView()
imageView.image = MaterialIcon.check?.imageWithColor(MaterialColor.white)
imageView.backgroundColor = MaterialColor.blue.accent2
imageView.frame = CGRectMake(1, 1, 20, 20)
imageView.layer.cornerRadius = imageView.frame.height/2
imageView.clipsToBounds = true
if indexPath.section == 0 {
imageView.tag = indexPath.row+4000
} else {
imageView.tag = indexPath.row+5000
}
print("IMAGEVIEW …Run Code Online (Sandbox Code Playgroud) 当我创建项目\xef\xbc\x8cin“常规”->“部署信息”时,我选择了iOS 15。但现在我需要将版本设置为iOS 14。我在“部署信息”中将其更改为iOS 14,但是当我运行我收到错误:
\n\n\n\n命令 MergeSwiftModule 失败,退出代码为非零\n:0: 错误:针对 iOS 14.0 进行编译,但模块“project”的最低部署目标为 iOS 15.0:
\n
我查看了一些相关问题,但他们提到了 pod,而我没有引入任何第三方软件包。
\nios ×8
swift ×5
appdelegate ×2
objective-c ×2
admob ×1
bluetooth ×1
deinit ×1
ios-darkmode ×1
ios13 ×1
iphone ×1
nstimer ×1
sql ×1
swiftui ×1
xcode ×1