Commit ec409e984148b6f8364a5d68ceac76f55d166291
1 parent
55ad1dc7
快速切换 影视剧和电商频道 导致的闪退问题
Showing
1 changed file
with
118 additions
and
112 deletions
metaCode/Classes/Main/HuBiLieHomePage/Controller/CNLiveTVHomeViewController.swift
| @@ -248,142 +248,148 @@ class CNLiveTVHomeViewController:CNLiveBaseViewController, UITableViewDataSource | @@ -248,142 +248,148 @@ class CNLiveTVHomeViewController:CNLiveBaseViewController, UITableViewDataSource | ||
| 248 | return self.dataArray.count | 248 | return self.dataArray.count |
| 249 | } | 249 | } |
| 250 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | 250 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| 251 | - | ||
| 252 | - if let slideModel = self.dataArray[indexPath.row] as? CNLiveDownSlideModel{ | ||
| 253 | - if slideModel.type == SlideModelTypeRecommend1{ | ||
| 254 | - //banner | ||
| 255 | - guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeYingshiBannerCellIdentifier) as? CNLiveHomeYingshiBannerCell | ||
| 256 | - else { | ||
| 257 | - let cell = CNLiveHomeYingshiBannerCell() | ||
| 258 | - return cell | ||
| 259 | - } | ||
| 260 | - cell.slideModel = slideModel | ||
| 261 | - return cell | ||
| 262 | - }else if slideModel.type == SlideModelTypeLanmu22{ | ||
| 263 | - //栏目 | ||
| 264 | - guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeLanmuCellIdentifier) as? CNLiveHomeLanmuCell | ||
| 265 | - else { | ||
| 266 | - let cell = CNLiveHomeLanmuCell() | 251 | + if indexPath.row < self.dataArray.count{ |
| 252 | + if let slideModel = self.dataArray[indexPath.row] as? CNLiveDownSlideModel{ | ||
| 253 | + if slideModel.type == SlideModelTypeRecommend1{ | ||
| 254 | + //banner | ||
| 255 | + guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeYingshiBannerCellIdentifier) as? CNLiveHomeYingshiBannerCell | ||
| 256 | + else { | ||
| 257 | + let cell = CNLiveHomeYingshiBannerCell() | ||
| 258 | + return cell | ||
| 259 | + } | ||
| 260 | + cell.slideModel = slideModel | ||
| 267 | return cell | 261 | return cell |
| 268 | - } | ||
| 269 | - cell.slideModel = slideModel | ||
| 270 | - cell.imgClickBlock = { slideContentMdl in | ||
| 271 | - let urlString = slideContentMdl.thirdUrl | ||
| 272 | - if let url = URL(string: urlString){ | ||
| 273 | - // 使用 URLComponents 解析 URL | ||
| 274 | - let components = URLComponents(url: url, resolvingAgainstBaseURL: false)! | ||
| 275 | - // 获取查询项数组 | ||
| 276 | - let queryItems = components.queryItems | ||
| 277 | - // 遍历查询项数组,查找 pageId 的值 | ||
| 278 | - var pageId = "" | ||
| 279 | - for queryItem in queryItems ?? [] { | ||
| 280 | - if queryItem.name == "pageId" { | ||
| 281 | - pageId = queryItem.value ?? "" | ||
| 282 | - break | 262 | + }else if slideModel.type == SlideModelTypeLanmu22{ |
| 263 | + //栏目 | ||
| 264 | + guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeLanmuCellIdentifier) as? CNLiveHomeLanmuCell | ||
| 265 | + else { | ||
| 266 | + let cell = CNLiveHomeLanmuCell() | ||
| 267 | + return cell | ||
| 268 | + } | ||
| 269 | + cell.slideModel = slideModel | ||
| 270 | + cell.imgClickBlock = { slideContentMdl in | ||
| 271 | + let urlString = slideContentMdl.thirdUrl | ||
| 272 | + if let url = URL(string: urlString){ | ||
| 273 | + // 使用 URLComponents 解析 URL | ||
| 274 | + let components = URLComponents(url: url, resolvingAgainstBaseURL: false)! | ||
| 275 | + // 获取查询项数组 | ||
| 276 | + let queryItems = components.queryItems | ||
| 277 | + // 遍历查询项数组,查找 pageId 的值 | ||
| 278 | + var pageId = "" | ||
| 279 | + for queryItem in queryItems ?? [] { | ||
| 280 | + if queryItem.name == "pageId" { | ||
| 281 | + pageId = queryItem.value ?? "" | ||
| 282 | + break | ||
| 283 | + } | ||
| 284 | + } | ||
| 285 | + if pageId.count > 0{ | ||
| 286 | + let vc = CNLiveHomeLanmuController() | ||
| 287 | + vc.slideContentModel = slideContentMdl | ||
| 288 | + vc.pageId = pageId | ||
| 289 | + currentViewController()?.navigationController?.pushViewController(vc, animated: true) | ||
| 290 | + }else{ | ||
| 291 | + //跳转webView | ||
| 292 | + CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: slideContentMdl.model, contentId: slideContentMdl.contentId, pid: slideContentMdl.pid, shareUrl: slideContentMdl.shareUrl, thirdUrl: slideContentMdl.thirdUrl, title: slideContentMdl.title, s_to: slideContentMdl.s_to, trailerId: slideContentMdl.trailerId, controller: self, slideModel: nil) | ||
| 283 | } | 293 | } |
| 284 | } | 294 | } |
| 285 | - if pageId.count > 0{ | ||
| 286 | - let vc = CNLiveHomeLanmuController() | ||
| 287 | - vc.slideContentModel = slideContentMdl | ||
| 288 | - vc.pageId = pageId | ||
| 289 | - currentViewController()?.navigationController?.pushViewController(vc, animated: true) | ||
| 290 | - }else{ | ||
| 291 | - //跳转webView | ||
| 292 | - CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: slideContentMdl.model, contentId: slideContentMdl.contentId, pid: slideContentMdl.pid, shareUrl: slideContentMdl.shareUrl, thirdUrl: slideContentMdl.thirdUrl, title: slideContentMdl.title, s_to: slideContentMdl.s_to, trailerId: slideContentMdl.trailerId, controller: self, slideModel: nil) | ||
| 293 | - } | 295 | + |
| 294 | } | 296 | } |
| 295 | - | ||
| 296 | - } | ||
| 297 | - return cell | ||
| 298 | - }else if slideModel.type == SlideModelTypeTVOneBigTwoSmall2{ | ||
| 299 | - // | ||
| 300 | - guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeOneBigTwoSmallCellIdentifier) as? CNLiveHomeOneBigTwoSmallCell | ||
| 301 | - else { | ||
| 302 | - let cell = CNLiveHomeOneBigTwoSmallCell() | ||
| 303 | return cell | 297 | return cell |
| 304 | - } | ||
| 305 | - cell.slideModel = slideModel | ||
| 306 | - return cell | ||
| 307 | - }else if slideModel.type == SlideModelTypeAD31{ | ||
| 308 | - //广告 | ||
| 309 | - guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeADCellIdentifier) as? CNLiveHomeADCell | ||
| 310 | - else { | ||
| 311 | - let cell = CNLiveHomeADCell() | 298 | + }else if slideModel.type == SlideModelTypeTVOneBigTwoSmall2{ |
| 299 | + // | ||
| 300 | + guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeOneBigTwoSmallCellIdentifier) as? CNLiveHomeOneBigTwoSmallCell | ||
| 301 | + else { | ||
| 302 | + let cell = CNLiveHomeOneBigTwoSmallCell() | ||
| 303 | + return cell | ||
| 304 | + } | ||
| 305 | + cell.slideModel = slideModel | ||
| 306 | + return cell | ||
| 307 | + }else if slideModel.type == SlideModelTypeAD31{ | ||
| 308 | + //广告 | ||
| 309 | + guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeADCellIdentifier) as? CNLiveHomeADCell | ||
| 310 | + else { | ||
| 311 | + let cell = CNLiveHomeADCell() | ||
| 312 | + return cell | ||
| 313 | + } | ||
| 314 | + cell.slideModel = slideModel | ||
| 315 | + return cell | ||
| 316 | + }else if slideModel.type == SlideModelTypeTwoDuanJu5{ | ||
| 317 | + //一排3个 | ||
| 318 | + guard let cell = tableView.dequeueReusableCell (withIdentifier: kCNLiveHomeTwoDuanjuCellIdentifier) as? CNLiveHomeTwoDuanjuCell | ||
| 319 | + else { | ||
| 320 | + let cell = CNLiveHomeTwoDuanjuCell() | ||
| 321 | + return cell | ||
| 322 | + } | ||
| 323 | + cell.slideModel = slideModel | ||
| 312 | return cell | 324 | return cell |
| 325 | + }else if slideModel.type == SlideModelTypeShop29{ | ||
| 326 | + //官方周边 一排2个 | ||
| 327 | + guard let cell = tableView.dequeueReusableCell (withIdentifier: kCNLiveHomeTwoShopCellIdentifier) as? CNLiveHomeTwoShopCell | ||
| 328 | + else { | ||
| 329 | + let cell = CNLiveHomeTwoShopCell() | ||
| 330 | + return cell | ||
| 331 | + } | ||
| 332 | + cell.slideModel = slideModel | ||
| 333 | + return cell | ||
| 334 | + }else{ | ||
| 335 | + return UITableViewCell() | ||
| 313 | } | 336 | } |
| 314 | - cell.slideModel = slideModel | ||
| 315 | - return cell | ||
| 316 | - }else if slideModel.type == SlideModelTypeTwoDuanJu5{ | ||
| 317 | - //一排3个 | ||
| 318 | - guard let cell = tableView.dequeueReusableCell (withIdentifier: kCNLiveHomeTwoDuanjuCellIdentifier) as? CNLiveHomeTwoDuanjuCell | 337 | + }else if let followModel = self.dataArray[indexPath.row] as? CNLiveHomeFollowModel{ |
| 338 | + //正在追 | ||
| 339 | + guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeFollowCellIdentifier) as? CNLiveHomeFollowCell | ||
| 319 | else { | 340 | else { |
| 320 | - let cell = CNLiveHomeTwoDuanjuCell() | 341 | + let cell = CNLiveHomeFollowCell() |
| 321 | return cell | 342 | return cell |
| 322 | } | 343 | } |
| 323 | - cell.slideModel = slideModel | 344 | + cell.followModel = followModel |
| 324 | return cell | 345 | return cell |
| 325 | - }else if slideModel.type == SlideModelTypeShop29{ | ||
| 326 | - //官方周边 一排2个 | ||
| 327 | - guard let cell = tableView.dequeueReusableCell (withIdentifier: kCNLiveHomeTwoShopCellIdentifier) as? CNLiveHomeTwoShopCell | 346 | + }else if let categoryModel = self.dataArray[indexPath.row] as? CNLiveHomeShopCategoryModel{ |
| 347 | + //电商分类 一排三个 | ||
| 348 | + guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeShopCategoryCellIdentifier) as? CNLiveHomeShopCategoryCell | ||
| 328 | else { | 349 | else { |
| 329 | - let cell = CNLiveHomeTwoShopCell() | 350 | + let cell = CNLiveHomeShopCategoryCell() |
| 330 | return cell | 351 | return cell |
| 331 | } | 352 | } |
| 332 | - cell.slideModel = slideModel | 353 | + cell.slideModel = categoryModel |
| 333 | return cell | 354 | return cell |
| 334 | }else{ | 355 | }else{ |
| 335 | - return UITableViewCell() | ||
| 336 | - } | ||
| 337 | - }else if let followModel = self.dataArray[indexPath.row] as? CNLiveHomeFollowModel{ | ||
| 338 | - //正在追 | ||
| 339 | - guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeFollowCellIdentifier) as? CNLiveHomeFollowCell | ||
| 340 | - else { | ||
| 341 | - let cell = CNLiveHomeFollowCell() | ||
| 342 | - return cell | ||
| 343 | - } | ||
| 344 | - cell.followModel = followModel | ||
| 345 | - return cell | ||
| 346 | - }else if let categoryModel = self.dataArray[indexPath.row] as? CNLiveHomeShopCategoryModel{ | ||
| 347 | - //电商分类 一排三个 | ||
| 348 | - guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeShopCategoryCellIdentifier) as? CNLiveHomeShopCategoryCell | ||
| 349 | - else { | ||
| 350 | - let cell = CNLiveHomeShopCategoryCell() | ||
| 351 | - return cell | ||
| 352 | } | 356 | } |
| 353 | - cell.slideModel = categoryModel | ||
| 354 | - return cell | ||
| 355 | }else{ | 357 | }else{ |
| 356 | - return UITableViewCell() | 358 | + |
| 357 | } | 359 | } |
| 358 | - | 360 | + return UITableViewCell() |
| 359 | } | 361 | } |
| 360 | func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | 362 | func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { |
| 361 | - | ||
| 362 | - if let slideModel = self.dataArray[indexPath.row] as? CNLiveDownSlideModel{ | ||
| 363 | - //非短剧 | ||
| 364 | - let slideModel = self.dataArray[indexPath.row] as! CNLiveDownSlideModel | ||
| 365 | - if slideModel.type == SlideModelTypeFollow77{ | ||
| 366 | - return 0.0//追剧 占位数据 | 363 | + if indexPath.row < self.dataArray.count{ |
| 364 | + if let slideModel = self.dataArray[indexPath.row] as? CNLiveDownSlideModel{ | ||
| 365 | + //非短剧 | ||
| 366 | + let slideModel = self.dataArray[indexPath.row] as! CNLiveDownSlideModel | ||
| 367 | + if slideModel.type == SlideModelTypeFollow77{ | ||
| 368 | + return 0.0//追剧 占位数据 | ||
| 369 | + } | ||
| 370 | + return CGFloat(slideModel.cellH) | ||
| 371 | + }else if let slideModel = self.dataArray[indexPath.row] as? CNLiveHomeFollowModel{ | ||
| 372 | + //正在追 | ||
| 373 | + return 50.0+15.0//80 | ||
| 374 | + }else if let slideModel = self.dataArray[indexPath.row] as? CNLiveHomeShopCategoryModel{ | ||
| 375 | + //商品分类 一排三个 | ||
| 376 | + let maxCount = slideModel.group.count > 4 ? 4 : slideModel.group.count | ||
| 377 | + // let hangNum = Int(ceil(Double(maxCount)/3.0)) | ||
| 378 | + // let imgW = (KSreenWidth-15*4)/3.0 | ||
| 379 | + // let imgH = imgW*32.0/105.0 | ||
| 380 | + let imgWH = 44.0 | ||
| 381 | + let titleH = 22.0 | ||
| 382 | + let rowH = imgWH+titleH+15.0 | ||
| 383 | + // let height = CGFloat(hangNum)*rowH | ||
| 384 | + let height = rowH | ||
| 385 | + return height | ||
| 386 | + }else{ | ||
| 387 | + | ||
| 367 | } | 388 | } |
| 368 | - return CGFloat(slideModel.cellH) | ||
| 369 | - }else if let slideModel = self.dataArray[indexPath.row] as? CNLiveHomeFollowModel{ | ||
| 370 | - //正在追 | ||
| 371 | - return 50.0+15.0//80 | ||
| 372 | - }else if let slideModel = self.dataArray[indexPath.row] as? CNLiveHomeShopCategoryModel{ | ||
| 373 | - //商品分类 一排三个 | ||
| 374 | - let maxCount = slideModel.group.count > 4 ? 4 : slideModel.group.count | ||
| 375 | -// let hangNum = Int(ceil(Double(maxCount)/3.0)) | ||
| 376 | -// let imgW = (KSreenWidth-15*4)/3.0 | ||
| 377 | -// let imgH = imgW*32.0/105.0 | ||
| 378 | - let imgWH = 44.0 | ||
| 379 | - let titleH = 22.0 | ||
| 380 | - let rowH = imgWH+titleH+15.0 | ||
| 381 | -// let height = CGFloat(hangNum)*rowH | ||
| 382 | - let height = rowH | ||
| 383 | - return height | ||
| 384 | }else{ | 389 | }else{ |
| 385 | - return 60 | 390 | + |
| 386 | } | 391 | } |
| 392 | + return 60 | ||
| 387 | } | 393 | } |
| 388 | 394 | ||
| 389 | func addRefreshView() { | 395 | func addRefreshView() { |