AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-6631314

user6631314's questions

Martin Hope
user6631314
Asked: 2025-04-30 01:59:39 +0800 CST

如何关闭 SwiftUI 视图以及如何通过所呈现的 SwiftUI 视图中的一个按钮来呈现 SwiftUI 视图

  • 6

我有一个使用 hostingController 呈现的 swiftUI 视图:

let hostingController = UIHostingController(rootView: FirstView)
 someVC.present(hostingController, animated: true)

FirstView 反过来使用 .sheet(IsPresented 和布尔值来呈现第二个 SwiftUI 视图,以确定是否应按如下方式显示它:

struct FirstView: View {
    @Environment(\.presentationMode) var presentationMode

    @State var showSecondView = false
//change showSecondView to true so it displays as a sheet

 .sheet(isPresented: $showSecondView) {
                SecondView() 
            }
}

在 SecondView 中,我想用一个按钮同时关闭 SecondView 和 FirstView。这个按钮可以关闭 SecondView,但我不知道如何同时关闭 FirstView,因为 FirstView 是在托管控制器中呈现的,没有使用布尔值。

如果 SecondView 是 First View 中的警报,那么我可以使用环境变量 presentationMode 来消除,但是,该变量似乎无法从 SecondView 访问。

 struct SecondView: View {
        @Environment(\.dismiss) var dismiss
    
    
    Button("OK") {
//THIS DOES NOT WORK BECAUSE presentationMode is out of scope
                presentationMode.wrappedValue.dismiss()
  
                dismiss()//
            }
    }

我怎样才能不仅关闭当前(或第二)工作表,而且还关闭在 hostingController 中呈现的呈现(或第一视图)。

提前感谢任何建议。

  • 2 个回答
  • 35 Views
Martin Hope
user6631314
Asked: 2025-01-12 06:18:32 +0800 CST

使用 PHP 访问已上传文件的信息并使用 GD 进行修改

  • 5

我正在上传包含在 $_FILES 对象中的图像。但是,当我尝试获取其大小时,我收到错误消息,提示它不是字符串或不是资源...我如何获取此图像的大小,然后在 GD 中修改它。我必须将其转换为字符串吗?或者这些方法需要什么作为输入。

$image = $_FILES['uploaded_file'];
var_dump($image);

$oldw = imagesx($image);
$oldh = imagesy($image);

$imagedetails = getimagesize($image);
$width = "width".$imagedetails[0];
$height = "height".$imagedetails[1];
$neww = 512;
$newh = 512;
$temp = imagecreatetruecolor($neww, $newh);
imagecopyresampled($temp, $image, 0, 0, 0, 0, $neww, $newh, $oldw, $oldh);

//Error messages:

imagesx() expects parameter 1 to be resource
imagesy() expects parameter 1 to be resource
getimagesize() expects parameter 1 to be string

//Here is what the var_dump of image 
array(5) {
  ["name"]=>
  string(14) "image.png"
  ["type"]=>
  string(24) "application/octet-stream"
  ["tmp_name"]=>
  string(14) "/tmp/phpLlon22"
  ["error"]=>
  int(0)
  ["size"]=>
  int(2743914)

提前感谢任何建议。

  • 1 个回答
  • 30 Views
Martin Hope
user6631314
Asked: 2024-12-29 02:43:09 +0800 CST

使用 PHP 从 api 响应中提取视频数据[重复]

  • 6
此问题这里已有答案:
如何使用 cURL 获取 JSON 数据并解码数据? (6 个答案)
PHP 使用 cURL 和带有标头的 GET 请求 (1 个答案)
14 小时前关闭。

我正在使用 PHP 中的以下 cURL 进行 API 请求,以获取 api 提供商推荐的视频文件。这就是他们的文档的范围。

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload_json);

$response = curl_exec($curl); 

当我将响应保存到文件然后在文本编辑器中查看它时,它看起来如下所示:

HTTP/1.1 200 OK
Date: Fri, 20 Dec 2024 21:23:34 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 3292160
Connection: keep-alive
Access-Control-Allow-Origin: *
x-request-id: a1d0850f892cb9b4fc357a3532e81b91
Server: cloudflare
CF-RAY: 8f52b1b34f7f8ff9-BOS
alt-svc: h3=":443"; ma=86400

{"video":"AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAlpQhtZGF0AAACrwYF//+r3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlID - 2 megs more of characters that are probably the video"}

ChatGPT 说要用字符串操作提取视频,例如搜索 \r\n\r\n 并删除所有内容,但我觉得一定有一种更干净的方法。

我怎样才能单独抓取视频并将其放入变量中。

提前感谢任何建议

  • 1 个回答
  • 34 Views
Martin Hope
user6631314
Asked: 2024-08-26 18:32:58 +0800 CST

使用 MYSQL 和 PHP 在单个查询中从同一张表中的两个记录中选择数据

  • 5

我有一个涉及 JOINS 和 Union 语句的 MYSQL 查询,通过该查询我查询多个表以生成 JSON 提要。(我对 MYSQL 不太熟悉,因此提前致歉。)

我现在必须添加评论。如果评论是关于单独表中的内容(例如文章),那么您可以对这两个表进行 JOIN。

我遇到的问题是,如果评论是关于评论的,我需要来自 sambe 表的两行信息,即新评论第 2 行,以及新评论所涉及的原始评论第 1 行。我不知道如何在单个查询中从一个表的两行中获取数据。我希望有一种方法或其他策略可以做到这一点。

这是该查询的简化版本。

Articles
id|text|pic|authorid

Users
id|name|pic

Comments
id|articleid|userid|commentid|text

SELECT a.id as 'itemid',a.text as 'body',a.pic as 'itempic',u.name as 'authorname',u.pic as 'authorpic', nil as 'subtext' 
FROM Articles `a`
LEFT JOIN 
Users `u` 
ON a.authorid = u.id 
UNION
Select c.id as 'itemid',c.comment as 'body',nil as 'itempic',u.name as 'authorname',u.pic as 'authorpic', cm.text as 'subtext' 
FROM COMMENTS `c`
/* THIS APPROACH DOES NOT SEEM TO WORK *?
LEFT JOIN 
COMMENTS `cm` 
ON cm.id = c.id
/* end approach */
LEFT JOIN 
Users `u` 
ON c.userid = u.id 
WHERE c.articleid = a.id 
GROUP by itemid

我这样做是否正确?或者您如何用相同的查询两次访问同一个表?感谢您的任何建议。

sql
  • 1 个回答
  • 34 Views
Martin Hope
user6631314
Asked: 2024-07-16 00:45:50 +0800 CST

澄清 PHP 如何处理真值和假值

  • 4

我想使用真/假结果在 PHP 中执行其他操作。我对以下情况感到惊讶:

$falsevar = false;
$truevar = true;
echo "falsevar which I just set to false is".$falsevar; //displays true
echo "truevar which I just set to true is".$truevar; //displays 1

输出:

falsevar which I just set to false istruevar which I just set to true is1

我该如何理解这个结果?为什么 PHP 会将 false 回显为 true?

更让我困惑的是,我的用例如下:

$prompt = "I would like a sandwich to eat";
$myarray = array("pizza", "hamburger", "hot dog");
$wantsItem = false;
foreach ($myarray as $needle) {
    if (strpos($prompt, $needle) != false) {
        echo "Match found: {$needle}\n";
$wantsItem = true;
    }
}
echo "wants item is".$wantsItem;

当我运行这个我认为应该返回 false 的程序时,什么也没有回响。

falsevar which I just set to false istruevar which I just set to true is1value of wants item

有人可以向我解释一下 PHP 中 true 和 false 的行为吗?(请注意,我理解true 和 false 不区分大小写,所以这不是问题。)

谢谢您的任何建议。

  • 3 个回答
  • 31 Views
Martin Hope
user6631314
Asked: 2024-07-05 19:35:49 +0800 CST

在 Swift 中将可选子字符串转换为字符串

  • 6

Apple 的文档和许多文章建议您只需调用即可将子字符串(string.subsequence)转换为字符串String(substring),事实上这是有效的。

let str = "Hello world"
let hello = str.prefix(5) //create substr
//CREATE STRING FROM SUBSTRING
let hellostr = String(hello) //works

但是,当子字符串是可选的,如下所示,

 let str = Optional("Hello world")
 let hello = str?.prefix(5) //create substr
 //CREATE STRING FROM OPTIONAL SUBSTRING
 let hellostr = String(hello) //gives error 

我收到了错误

"No exact matches in call to initializer "

什么原因可能导致这个错误?

谢谢您的任何建议。

swift
  • 1 个回答
  • 45 Views
Martin Hope
user6631314
Asked: 2024-07-01 21:06:10 +0800 CST

如何在 Swift 中循环遍历数组的一部分

  • 5

我想根据索引循环遍历 Swift 中数组的一部分,而不是整个数组。该数组来自 API,因此我事先不知道元素的数量。

例如对于数组["Joe's pizza","Sal's Pizza","Pizza Hut"],我只想循环到前三个(如果有三个)然后停止。在某些情况下,起始数组将少于 3 个元素,而在其他情况下则多于 3 个元素,具体取决于 API 返回的内容。

我的如下代码不起作用。

let myArray = ["Joe's","Sal's","Pizza Hut","Domino's","John's","Pizza King"]//from API. Could be more or less
let numElements = myArray.count
if numElements = 0 {
    print("none found")
    return
}
var i = 0
var str = ""
while i <= 2 {
    for i in 1...numElements-1 {
        print(i)
        str = myArray[i]
        print(str)
    }//end for loop
    i+=1
} // end while loop

代码将打印完整的 6,而不遵守 while 条件。如果我将 while 放在 for 循环中,它将不必要地遍历整个数组,尽管我只想要前 3 个,但这个数组可能很长

如何限制索引中使用的范围(当我不知道实际数组数量是否小于或大于我要寻找的数字时)。

谢谢您的任何建议。

arrays
  • 1 个回答
  • 27 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve