当前位置: 首页 > news >正文

网站建设全包需要多少钱外贸仿牌网站

网站建设全包需要多少钱,外贸仿牌网站,wordpress利于seo,北京智能网站建设企业我正在尝试实现一个 View #xff0c;该 View 可以在内容数组的大小发生变化时更改显示项目的数量(由 ForEach 循环创建)#xff0c;就像购物应用程序可能会在用户下拉刷新后更改其可用项目的数量一样 这是我到目前为止尝试过的一些代码。如果我没记错的话#xff0c;这些适… 我正在尝试实现一个 View 该 View 可以在内容数组的大小发生变化时更改显示项目的数量(由 ForEach 循环创建)就像购物应用程序可能会在用户下拉刷新后更改其可用项目的数量一样 这是我到目前为止尝试过的一些代码。如果我没记错的话这些适用于 Xcode beta 4但适用于 beta 5: 如果数组的大小增加循环仍将显示原始数量的元素数组的大小减小会导致索引超出范围错误 代码: import SwiftUIstruct test : View {State var array:[String] []State var label not pressedvar body: some View {VStack{Text(label).onTapGesture {self.array.append(ForEach refreshed)self.label pressed}ForEach(0..array.count){number inText(self.array[number])}} } }#if DEBUG struct test_Previews: PreviewProvider {static var previews: some View {test()} } #endif一般来说我是 SwiftUI 和 GUI 编程的新手感觉每个内容都是在启动时定义的之后很难进行更改(例如:在用户导航离开然后返回后重置 View ) .非常感谢循环问题的解决方案或使 View 更具动态性的任何提示! 最佳答案 Beta 5 发行说明说: The retroactive conformance of Int to the Identifiable protocol is removed. Change any code that relies on this conformance to pass .self to the id parameter of the relevant initializer. Constant ranges of Int continue to be accepted: List(0..5) {Text(Rooms) } However, you shouldn’t pass a range that changes at runtime. If you use a variable that changes at runtime to define the range, the list displays views according to the initial range and ignores any subsequent updates to the range. 您应该更改 ForEach 以接收一个数组而不是范围。理想情况下是 Identifiable 数组以避免使用 \.self。但根据您的目标这仍然有效: import SwiftUIstruct ContentView : View {State var array:[String] []State var label not pressedvar body: some View {VStack{Text(label).onTapGesture {self.array.append(ForEach refreshed)self.label pressed}ForEach(array, id: \.self) { item inText(item)}}} } 或者按照rob mayoff的建议如果您需要索引: struct ContentView : View {State var array:[String] []State var label not pressedvar body: some View {VStack{Text(label).onTapGesture {self.array.append(ForEach refreshed)self.label pressed}ForEach(array.indices, id: \.self) { index inText(self.array[index])}}} } 关于swift - 如何在数组大小更改后刷新 ForEach 显示元素的数量(SwiftUI、Xcode 11 Beta 5)我们在Stack Overflow上找到一个类似的问题 swift - How to refresh number of ForEachs displaying elements after arrays size changes (SwiftUI, Xcode 11 Beta 5) - Stack Overflow 具有非恒定范围视图刷新的Swift ForEach swift view swiftui-foreach 我知道这是一个简单的问题但我还没有找到答案。我想了解基本概念。 我试图用非常量范围更新ForEachclosing参数是分配给按钮的变量。 变量被赋予状态因此应该刷新视图。不知怎么的它不起作用了。 import SwiftUIstruct ContentView: View {State private var numberOfTimes 5let timesPicker [2,5,10,12,20]State private var tableToPractice 2enum answerState {case unansweredcase wrongcase right}func listRange(){}var body: some View {NavigationView{HStack{VStack{Form{Section {Picker(Tip percentage, selection: $numberOfTimes) {ForEach(timesPicker, id: \.self) {Text($0, format: .number)}}.pickerStyle(.segmented)} header: {Text(How many times do you want to practice?)}Section{Stepper(Table to practice: \(tableToPractice.formatted()), value: $tableToPractice, in: 2...16 )}Button(Start Now, action: listRange).buttonStyle(.bordered)List{ForEach(0..numberOfTimes){Text(Dynamic row \($0))}}}.foregroundColor(.gray)}}}} }struct ContentView_Previews: PreviewProvider {static var previews: some View {ContentView()} } 发布于 1 年前 ✅ 最佳回答 问题是没有确定范围。让我们排几行 struct Row: Identifiable {let id UUID()}然后设置一组可识别的项目 State private var numberOfTimes 5State private var rows Array(repeating: Row(), count: 5)现在您可以获得响应列表 List{ForEach(rows) { row inText(Dynamic row)}}调用更改时更新以重新创建阵列 .onChange(of: numberOfTimes) { newValue inrows Array(repeating: Row(), count: newValue)numberOfTimes newValue}应在表单上调用onChange。 当您能够更好地查看模型数据时这将更有意义有关更深入的示例请参阅apple文档。 这是针对lazy v stack的但我考虑的是数据模型设置 https://developer.apple.com/documentation/swiftui/grouping-data-with-lazy-stack-views 最终解决办法将FOREACH的列表改为Published属性即可。
http://www.hkea.cn/news/14522331/

相关文章:

  • 常用网站开发语言优缺点克拉玛依市住房和建设局网站
  • 常设中国建设工程法律网站wordpress 图片收录
  • 网站群 建设 方案高端制作网站服务
  • 开发 程序网站深夜小网站
  • 免费网站模板下载网站网站扫码怎么做的
  • 保定专业网站建设公司做科学实验的网站
  • 深圳网站开发哪些安装app
  • seo网站推广方法网站制作的预算
  • 上海个人网站建设百度收录申请入口
  • 域名购买成功后怎么做网站设计师培训ui设计
  • 做网站销售门窗怎么做wordpress菜单选项
  • 商务网站建设平台在线网站建设活动
  • 十大最免费软件排行榜无锡seo报价
  • 湖南长沙网站建设公司如何在阿里云主机安装wordpress
  • 建德市建设局网站建筑工程网上超市
  • logo和网站主色调三项措施做好门户网站建设
  • wordpress 标题截断百度自动优化
  • 建设投票网站的目的个人主页自助建站
  • 网站运营是什么手机端网站尺寸规范
  • 网站建设财务怎么入账wordpress出不来安装界面
  • 八旬老太做直播 什么网站电器网站建设策划书
  • 网站建设选题意义被忽悠去做网销了
  • 页面设计排版网站百度升级最新版本下载安装
  • 网站建设会议纪要python网站开发效率
  • 精品国内网站建设wordpress 加入 swf
  • 企业网站建设主要类型及选择做品牌网站哪个好点
  • 网站建设z亿玛酷1订制电脑网站转换手机网站怎么做
  • 江苏省建设厅网站建造师强制注销网站自动抢注
  • 网站标题就一个关键词做营销型网站费用
  • 宝石网站建设网站的栏目设计