In my Table View I have the label text set to a different colour if the name is in the Flagged Array (flaggedNames). The correct cell labels turn red but as I scroll the text of other labels are also red. This changes as I scroll.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let name = names[indexPath.row]
cell.textLabel?.text = name
if flaggedNames.contains(meterNumber) {
cell.textLabel?.textColor = .systemRed
}
return cell
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm trying to access another class in my CollectionView Controller but when I try and initialise the class I get the error
Here is the class
@MainActor
class AlbumsViewModel {
private let albumService: AlbumService
private let favouritesService: FavouritesService
private let recommendationService: RecommendationService
@Published var favourites = [Bool]()
@Published var recommendedAlbums = [Album]()
@Published var allAlbums = [Album]() {
didSet {
updateFavourites()
}
}
init(albumService: AlbumService, favouritesService: FavouritesService, recommendationService: RecommendationService) {
self.albumService = albumService
self.favouritesService = favouritesService
self.recommendationService = recommendationService
}
...(functions here)
Collectionview Controller Class
class CVC: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var viewModel: AlbumsViewModel
init?(viewModel: AlbumsViewModel, coder: NSCoder) {
self.viewModel = viewModel
super.init(coder: coder)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delaysContentTouches = false
Task {
print(viewModel.allAlbums)
}
} // End viewDidLoad
...
Trying to recreate this https://martinmitrevski.com/2021/07/11/ml-recommendation-app-with-create-ml-on-ios-15/
In my tableview I have a few custom cells. When I scroll in the tableview it lags in the same spot but only for the first time the app is open. if I go back to the root view then open the tableview again it doesn't seem to lag. I've traced the lag to one cell. In that cell I have an embedded collection view and each of those cells has image view with is showing a MKMapSnapshot and also a few labels etc. If run with 0 collectionView cells (numberOfCellsInSection) the tableview scrolls smoothly but lags when I have 1 or more CollectionViewCell cells.
I initially loaded the image in the collectionView cell class in layoutSubviews which worked but I then learned that this is called numerous times so code like that shouldn't be there. if I put it in awakeFromNib the Branch struct doesn't seem to have been passed to the cell as yet (from cellForRowAt) so it doesn't work there. I then moved setting the image in cellForItemAt but I'm still not sure if it is correct there.
// Table View cellForRowAt
case .branchesCell:
let cell = tableView.dequeueReusableCell(withIdentifier: "branchesCell", for: indexPath) as! BranchesCell
cell.branches = restaurant?.branches // This is the info the embedded collectionView cell should display. Text for labels and coordinates for the MKMapSnapshot.
return cell
// TableView Cell Class
class BranchesCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet var collectionView: UICollectionView!
var branches: [Branch]?
var restaurantName = String()
override func awakeFromNib() {
super.awakeFromNib()
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = .clear
collectionView.delaysContentTouches = false
}
// MARK: UICollectionView
func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 }
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if let branches = branches {
return branches.count
} else { return 0 }
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! NestledBranchCell
cell.layer.masksToBounds = false
cell.backgroundColor = .clear
let imageView = cell.viewWithTag(1) as! UIImageView
if let branches = branches {
cell.branch = branches[indexPath.row]
cell.restaurantName = restaurantName
// Tried to run this in a different thread to see if it would make a difference.
DispatchQueue.main.async() { [self] in
let size = CGSize(width: 314, height: 195)
// Set the image here
getMapImage(branch: branches[indexPath.row], size: size) { mapImage in
imageView.image = mapImage
}
}
}
return cell
}
func getMapImage(branch: Branch, size: CGSize, completion: @escaping (UIImage?) -> ()) {
var mapImage = UIImage()
let mapSnapshotOptions = MKMapSnapshotter.Options()
let location = branch.coordinates.coordinate
let region = MKCoordinateRegion(center: location, latitudinalMeters: 300, longitudinalMeters: 300)
mapSnapshotOptions.region = region
mapSnapshotOptions.scale = UIScreen.main.scale
mapSnapshotOptions.size = size
mapSnapshotOptions.showsBuildings = true
mapSnapshotOptions.pointOfInterestFilter = .none
let snapShotter = MKMapSnapshotter(options: mapSnapshotOptions)
snapShotter.start { snapshot, error in
let image = snapshot?.image
mapImage = image!
completion(mapImage)
}
}
}
I removed a pod from my project and when I went to commit I got a whole list of the deleted files marked with exclamation marks saying they're "missing". I've cleaned the build folder, deleted derived data etc but these still keep coming up.
I'm looking to get a GPU to use for Object capture. The requirements are an AMD GPU with 4GB of VRAM and ray tracing support, the rx 580 seems to be able to do ray tracing from what I've found online but looks like someone had an issue with a 580X here https://developer.apple.com/forums/thread/689891
I have an ARSCNView with nodes in AR. The UI guides you in scaling an object and the images captured are used to create a 3D model. When I try take a picture using arView.snapshot() it basically takes a screenshot a the resolution is the screen resolution and the nodes are visible. I also noticed that the AR View displays a lower quality output than the camera app.
If I try get a separate camera output with AVFoundation then the arView doesn't get an output and vive versa, it only allows one view to access the camera.
Is it possible to get a full resolution image without the nodes visible from the AR View (if I hide them, capture the image and display them again they do flicker) or is it possible to have 2 camera streams one to the arView and the other used to solely capture images (this one does not need to visible on screen)
I have a basic List made in SwiftUI. When I scroll with the Digital Crown I get the "light haptics" however when I get to the top or bottom of the list I don't get the more pronounced dent.
Update - If I use a plain list style then I get the haptics as expected. However it should work with the elliptical style as this is used in the system.
The console outputs the following
2022-05-19 23:32:53.782614+0200 WatchApp WatchKit Extension[326:41020] [default] Error: Error Domain=NSOSStatusErrorDomain Code=-536870187 "(null)"
2022-05-19 23:32:53.783181+0200 WatchApp WatchKit Extension[326:41020] [detents] could not play detent NO, 2, Error Domain=NSOSStatusErrorDomain Code=-536870187 "(null)", (
{
Gain = "0.01799999922513962";
OutputType = 0;
SlotIndex = 4;
},
{
Gain = "0.4900000095367432";
OutputType = 1;
SlotIndex = 5;
}
)
Here is my code
struct ContentView: View {
var body: some View {
List {
ForEach(0..<100) { i in
NavigationLink(destination: FeedView()) {
Text("Hello")
}
}
}.navigationTitle("Title")
}
}