小编Cha*_*ong的帖子

无法将IBOutlet从storyboard连接到UIView子类

我可以右键单击并从我的自定义UIView子类文件拖动到storyboard元素以连接它们,但无法通过其他方式执行此操作.我相信这是一个Xcode错误.有什么办法可以解决这个问题吗?这不是第一次它已经发生并且令人讨厌.

我已经尝试过多次清理和重启Xcode而没有运气.

这不起作用 这不起作用(右键单击从故事板到Swift文件)

这有效 这是有效的(右键从swift文件的IBAction到故事板)

顺便说一下,我正在使用Xcode 8.1和Swift 3.0.

更新:我不是在寻找如何连接IBOutlets/IBActions的答案,因为正如我上面提到的那样(以及截图中),我已经能够连接它们并且应用程序运行良好.问题是更多关于为什么Xcode不允许我从Storyboard> Swift文件连接,但让我从Swift文件> Storyboard这样做.如果这个问题具有误导性,我很抱歉.

xcode interface-builder ios xcode-storyboard swift

22
推荐指数
4
解决办法
2万
查看次数

Xcode 8 App安装失败,出现未知错误

错误讯息[1]

我尝试在iOS设备上运行项目时发生以下错误.在模拟器上运行它可以正常工作.

另一个奇怪的事情是我能够在我的设备上运行我的其他项目,只有这个给我这个错误的特定项目.

我尝试了所有我能找到的解决方案:

  1. 清理项目,删除派生数据
  2. 重新启动Xcode,我的Mac和我的iOS设备
  3. 取消选择测试目标中的"自动管理签名".
  4. 我无法从我的设备中删除该应用并重新安装它,因为它之前未安装在我的设备上.

任何帮助对我来说意味着很多!我正在使用Xcode 8.1和Swift 3.0,在iOS 10.1.1设备上运行.

xcode ios xcode8

17
推荐指数
1
解决办法
1万
查看次数

axios 错误 转换后的数据必须是字符串、ArrayBuffer、Buffer 或 Stream

尝试使用 axios 执行 POST 请求时出现此错误:

Error: Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream at createError

这是我的要求:

async function fetchAndHandleErrors() {
  const url = `/claim/${claimId}`;
  const headers = {
    Accept: 'application/json',
    Authorization: `Bearer ${token}`,
  };

  const body = new FormData();
  body.append('damage_description', damageDescription);
  body.append('damaged_phone', {
    uri: imageUri,
    type: 'image/jpeg', // or photo.type
    name: imageUri,
  });

  const result = await axios({
    'post',
    url: `${baseUrl}${url}`,
    data: body,
    headers,
  });
  return result.data;
}

Run Code Online (Sandbox Code Playgroud)

我尝试删除result.data但仍然得到相同的错误。这是为什么?

javascript react-native axios

8
推荐指数
1
解决办法
3467
查看次数

当python进程被杀死时运行atexit()

我有一个在后台运行的python进程,我希望它只在脚本终止时生成一些输出.

def handle_exit():
    print('\nAll files saved in ' + directory)
    generate_output()

atexit.register(handle_exit)
Run Code Online (Sandbox Code Playgroud)

调用引发KeyboardInterupt异常并正确sys.exit()调用handle_exit(),但是如果我kill {PID}要从终端执行它会终止脚本而不调用handle_exit().

有没有办法终止在后台运行的进程,并handle_exit()在终止之前仍然运行它?

python atexit background-process

7
推荐指数
1
解决办法
4106
查看次数

iOS Swift Local通知没有"弹出"

我正在尝试在预定时间发送本地通知.但是通知没有出现在屏幕上,但是当我向下滑动时它会显示在通知中心.

这就是我想要实现的目标.这就是我所得到的.
       

这段代码来自我的AppDelegate的didFinishLaunchingWithOptions().

    // Setup local push notifications
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound], categories: nil))
    scheduleNotifications()
Run Code Online (Sandbox Code Playgroud)

这是scheduleNotifications()的代码

func scheduleNotifications() {
    // create a corresponding local notification
    let notification = UILocalNotification()

    // Get today's date, time and year
    let calendar = NSCalendar.currentCalendar()
    let components = calendar.components([NSCalendarUnit.Day, NSCalendarUnit.Month, NSCalendarUnit.Year], fromDate: NSDate())
    // Sets the fire time to 2pm/1400 hours to anticipate user for lunch time
    components.hour = 19
    components.minute = 13
    components.second = 00

    notification.fireDate = components.date             // Sets …
Run Code Online (Sandbox Code Playgroud)

xcode notifications local ios swift

6
推荐指数
1
解决办法
5082
查看次数

将 React Native FlatList 滚动到负偏移量

我有一个FlatList,我正在实现一个自定义拉动刷新,其想法是将其滚动到负偏移量,以在释放时显示其下方的动画。这是我的代码FlatList

const flatListRef = useRef(null);

const handleRelease = () => {
    flatlistRef.current.scrollToOffset({ y: -100 });
    setTimeout(() => {
        flatlistRef.current.scrollToOffset({ y: 0 });
    }, 1000)
}

return (
    <FlatList
        data={data}
        renderItem={({ item }) => {
            return (
                <View style={styles.row}>
                    <Text style={styles.text}>{item}</Text>
                </View>
            )
        }}
        onScroll={onScroll}
        scrollEventThrottle={16}
        onResponderRelease={handleRelease}
        ref={flatListRef}
    />  
)
Run Code Online (Sandbox Code Playgroud)

释放后,FlatList应该滚动到偏移 -100 以显示下面的动画,然后在 1 秒后向上滚动。但发生的情况是它滚动到偏移 0(我可以看出,因为我尝试在释放后立即向下滚动,它会立即尝试向上滚动)。

是否可以以编程方式滚动FlatList到负偏移量?

javascript scroll react-native react-native-flatlist

3
推荐指数
1
解决办法
6506
查看次数

使用 AudioConverter Swift 将 .m4a 文件转换为 .aiff

我正在尝试使用这篇文章中的答案将给定的 .m4a 格式音频文件转换为 .aiff 格式。我已将代码转换为 Swift 3.0。

func convertAudio(_ url: URL, outputURL: URL) {
    var error : OSStatus = noErr
    var destinationFile : ExtAudioFileRef? = nil
    var sourceFile : ExtAudioFileRef? = nil

    var srcFormat : AudioStreamBasicDescription = AudioStreamBasicDescription()
    var dstFormat : AudioStreamBasicDescription = AudioStreamBasicDescription()

    var audioConverter : AudioConverterRef? = nil

    ExtAudioFileOpenURL(url as CFURL, &sourceFile)

    var thePropertySize: UInt32 = UInt32(MemoryLayout.stride(ofValue: srcFormat))

    ExtAudioFileGetProperty(sourceFile!, kExtAudioFileProperty_FileDataFormat, &thePropertySize, &srcFormat)

    dstFormat.mSampleRate = 44100  //Set sample rate
    dstFormat.mFormatID = kAudioFormatLinearPCM
    dstFormat.mChannelsPerFrame = 1
    dstFormat.mBitsPerChannel = 16 …
Run Code Online (Sandbox Code Playgroud)

audio avfoundation swift

2
推荐指数
1
解决办法
2696
查看次数

无法在Xcode Playgrounds中初始化UICollectionView

我试图初始化UICollectionView:

import UIKit
import PlaygroundSupport

let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
Run Code Online (Sandbox Code Playgroud)

但是我得到的只是

error: Execution is interrupted, reason: signal SIGBART
Run Code Online (Sandbox Code Playgroud)

xcode uicollectionview swift swift-playground

1
推荐指数
1
解决办法
148
查看次数

Python回文程序不起作用

我在python中写了一个简单的程序,检查句子是否是回文.但我无法弄清楚为什么它不起作用.结果总是错误的.有谁知道什么是错的?

def isPalindrome(word):
    # Removes all spaces, and lowercase the word.
    word = word.strip().lower()
    word = word.replace(" ", "")

    # If the length of the word is less than 1, means its a palindrome
    if (len(word) <= 1):
        return True

    # Compares the first and the last character of the word.
    # If it is the same, calls the function again with the same word,
    # without its first and last characters. If its not the same, its
    # not …
Run Code Online (Sandbox Code Playgroud)

python recursion palindrome

0
推荐指数
2
解决办法
679
查看次数