This is a followup question to a question previously asked before.
didselectatrow updating multiple cells below reloaded tableview + counter
So after much reading and experimenting even after I accepted the guys answer I am still having the same issue. I am going to try a much different approach to it after reading around I found use of adding/removing the index path by having a Set <NSIndexPath>() var that I am constantly checking.
After much experimentation I finally got a working check on the Set <NSIndexPath> the problem is for some reason in xcode 7 when I try to create a second array to capture the integer values related to the set xcode freezes up on indexing. Which is altogether a different issue. How do I go about keeping track of not only the indexpath row but also the counter as well? My latest code to insert/remove indexpaths at row is:
if indexCount == 1 || indexCount == 2 {
CountIndex.insert(indexPath)
} else {
CountIndex.remove(indexPath)
}
My latest try was to try creating a dictionary that stores the indexpath + the Counter in a dictionary like so var cardCountindexCount = [NSIndexPath: Int]()
Then setting it in the func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { by cardCountindexCount = [indexPath: cardCount]. However I am lacking any experience on going about this approach as it is all experimental and it seems that what I get when I try to recall this is a similar problem. Instead of actually changing the text label in the didselectatrow I am now trying to change it in cellforrow method and creating a universal variable that can store the data changes.
I am willing to admit I am slightly out of my depths on this problem as I have only ever worked with simple tableviews prior. More guidance would be greatly appreciated!
The way I ended up fixing this was by setting the relationship in core data, then saving the quantity of the card in core data, and finally recalling the object relationship and quantity back into the func tableview willDisplayCell method showing the changes in text in that method.
Related
Update: this problem is more focused now, and not on quite the same topic. I've asked this question as a follow-on
ORIGINAL QUESTION:
I am getting a crash on a subclassed WKWebView-provisioned app.
ProcessAssertion::acquireSync Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=87121, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
The problem is, that I can't tell if this is related or not. The actual error on crash is
Thread 1: EXC_BAD_ACCESS (code=1, address=0xbdb2dfcf0470)
Which I was assuming was something running off the end of an array. This makes some sense: I'm selecting from a table that filters out some entries from the data source; but I've checked that carefully; there is no point when a row index greater than the actual rows is accessed (and yes, I'm accounting for the difference between count and index).
The main change here is that I previously had a UIView that acted as a container for a number of CAShapeLayers. I also wanted to overlay text view, but with the proviso that this be via a WKWebView. With two separate views, I would have to either have the CAShapeLayer objects in front of, or behind the WebView. I was seeking a fix to that.
What I have done is substitute a WKWebView for the original UIView. I can add the CAShapes to it, so it performs the original function. It also can, presumably, display the html. And the original suggestion in this answer to a question I asked is what I am working towards. The idea being that it would allow the effect sought, with shapes in front of or behind the html elements.
But the error is thrown after the DidSelect call on the table:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Tracker.track("getting row \(indexPath.row)")
let ptv = tableView as? NovilloTableView
if ptv!.uiType == .textTable {
let gp = Projects.currentProject?.getPaths(type: PaletteView.getCurrentPane())
GitPaths.currentGitPath = gp![indexPath.row]
NotificationCenter.default.post(name: NNames.updateWebText.nn(), object: nil)
return
}
let svgs = Projects.currentProject!.getPaths(type : PaletteView.getCurrentPane())
var gitPath = svgs[indexPath.row]
var gitPaths = GitPaths.getMediaBoundingBoxes(paths: [gitPath])
guard let pathArrays = gitPath.parseForRegBeziers() else { return }
let rslt = pathArrays.0
let regBeziers = pathArrays.1
gitPath.boundingBox = gitPath.getBoundsParamsForPaths(src: regBeziers.isEmpty ? rslt : regBeziers)
GitPaths.currentGitPath = gitPath
// Tracker.track("sending notification")
NotificationCenter.default.post(name: NNames.updateMedia.nn(), object: nil,
userInfo: ["path" : gitPath])
Tracker.track("completed didSelect")
return
}
In other words, the interaction has ended; but I get this crash, even though I can se that the expected result (the rendering of the shapes into the view) has been completed correctly. It seems to be happening right after everything has completed, and no amount of breakpoints has shown anything else to be happening.
This is confusing to me, and I have hit a limit on what I know how to do to dig further into this. Given the nature of web connections, I've wondered if it's some asynchronous issue that I can't debug sequentially; but that's guesswork without any direct evidence.
I suspect that there is a possible configuration problem with the WebView that shows up once I interact with it, by changing its contents. I'm not actually trying to get it to load anything when it crashes, it's only performing its original function as a container for the CAShapeLayers, so I'm confused.
The main view that contains the WKWebView (which is subclassed, to support a function to determine if it should display the web content, and which I've commented out), is set as the delegate for the WKWebView, and that seems to be fine, though there are no actual protocol functions added to that view, not sure if that matters.
The other detail is that the WebView when it does load web content is only loading local text, and not connected to any services. This testing is happening in the Simulator, and I've come across advice elsewhere to allow for background processes that include enabling Background Fetch, etc., but this has done nothing to change the situation...
EDIT: this is the extent of the configuration of the subclassed WKWebView: maybe this is the issue?
mediaDisplay = NovilloWebView()
mediaPane.addSubview(mediaDisplay)
mediaDisplay.navigationDelegate = self
mediaDisplay.uiDelegate = self
mediaDisplay.backgroundColor = .clear
I have a pretty simple UICollectionView that for some reason does not reloadData() as I would expect after a filter is applied. I am getting the right values into the filtered array, but I am getting rogue cells in the collection view that do not clear until scrolled - dequeued.
In some cases it works fine. I've yet to understand the condition in which it doesn't.
I have an array of objects master, and an array that is used to hold values that are filtered from that master array, ie:
hourly = hourlyMaster.filter { $0.forecastDateTime >= minDate }`
The cellForItemAt functionality all works fine. I just want the view to redraw after I apply the filter to the array. Apparently,
hourlyCollectionView.reloadData()
immediately following the filter is not getting it done. I'm sure there is something easy I'm missing here. ANY ideas are greatly appreciated.
Try putting the reloadData() in the hourly array's didSet to always reload the collection view when the data source is updated. You may be calling reloadData() faster than the filter function is executing.
var hourly: [Date] = [] {
didSet {
hourlyCollectionView.reloadData()
}
}
Never did get a viable solution or figure this out. Found a radar from a little while back... here.
The workaround is simply to use yourCollectionView.reloadSections()
That solved my issue. I'm not absolutely certain if there is another variable in my circumstance that caused this issue, but nothing else worked.
I made a NSTableview and a custom tablecellview-class "KSTablecellview" which defines the cells inside the tableview.
Now I'm trying to access these cells and the elements inside them at a certain time, for example triggered through an users input.
For example I wanna change the text of a textfield in one of my custom cellviews. I tried that:
Outlet_TableView.selectRowIndexes(IndexSet(integer: 0), byExtendingSelection: false) // Selecting row #1
let view = Outlet_TableView.view(atColumn: 0, row: 0, makeIfNecessary: false) as! KSTableCellView // getting cellview, at first row/ first column (-> crashes)
view.myTextField.stringvalue = "Hello World"
This fails giving me "[...] [default] Unable to load Info.plist exceptions (eGPUOverrides)"
I tried some other things and tried to work out the problems reason, but I wasn't able to do it, I'm still a beginner.
Any help would be really great.
I'm using XCode and Swift, trying to build an app for Mac OS.
You should try to avoid updating the content of your cells manually. Instead, you should reload the data from your data source.
func reloadData(forRowIndexes rowIndexes: IndexSet,
columnIndexes: IndexSet)
Which will in turn fetch the data from your data source at the given index/column.
For example, your data source would probably contain "Hello World" at the given index after the user event occurred (provided you updated your data source content), and would thus be used in the dataCellFor: delegate method.
May be you're doing these operations before table is loaded for the first time(eg. inviewDidLoad) or on tableView with numberOfRows = 0.
Until tableView loads that row, it won't create the views inside that row and tableView.view(atColumn:, row:, makeIfNecessary: false) will return nil and force unwrapping this nil will make your application crash.
I am facing an issue while displaying google maps in a table view cell with swift. I want to display check In (Latitude and Longitude) based on this I want to display google map in table view. I will latitude and longitude from server if no location available means I will get null. so, In one scenario I am getting correct, but while reloading the top-level I am getting map when and where their latitude and longitude is null also. Please guide me.
A map view is an expensive view to instantiate. Even when using dequeueReusableCellWithIdentifier it will still be resource-heavy with a large number of items.
I believe using a way to generate a static map image from your longitude/latitude combination is your best bet.
You can take a look here and you can see how to easily construct an API call to many popular map providers such as Google for a static image map like for example:
http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=13&scale=false&size=600x300&maptype=roadmap&format=png&visual_refresh=true
Also worth mentioning that some of those providers might have limitations (Like Google might need an API key in case of high traffic). So choose wisely after some research.
Looks like you are facing two issues
1) Already mentioned one "Map appears even when data is nil"
2) Performance issue (It is not mentioned here though)
The first one is due to dequeueing of cell. When you reload table , the cell will be reused(Not created again).
When you return your cell for row in
tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
the cell with map view may get return, that is why you get unwanted map there. You should make it nil to prevent this.
2:
When came to performance, its a not the right approach to show mapview in every cell. An alternate approach is to make image out of your map url
use this
let mapUrl: String = NSURL(string:"YourMapURL")
let mapImage = UIImage.imageWithData(NSData.dataWithContentsOfURL(mapUrl))
let latitude:Double = 17.3850
let longitude:Double = 78.4867
let imageURL = NSURL(string: "http://maps.googleapis.com/maps/api/staticmap?center=\(latitude),\(longitude)&zoom=12&scale=false&size=600x300&maptype=roadmap&format=png&visual_refresh=true")
let imagedData = NSData(contentsOfURL: imageURL!)!
staticMapImgView.image = UIImage(data: imagedData)
I am in the process of transitioning over to Swift from Obj-C and I think I have a fairly good understanding of the ? ! concepts. I am however experiencing a bad access crash on a field that is nil.
I am using
var cell :ContactIInfoTableViewCell!
cell = tableView.dequeueReusableCellWithIdentifier("notes", forIndexPath: indexPath) as! ContactIInfoTableViewCell
if let clinic = receivedVisitDetails?.clinicNotes {
cell.textLabel?.text = clinic
}
Which produces the error if empty. My understanding was that the IF statement would stop this issue but it hasn't.
What am I doing wrong here?
UPDATE
This is a detail view for the core data fetch.
NSManagedObject is set as
var receivedVisitDetails: VisitDetails! = nil
The prepareForSeague on the previous view
let visits:VisitDetails = fetchedResultsController.objectAtIndexPath(indexPath!) as! VisitDetails
taskController.receivedVisitDetails = visits
The crash only happens when the clinicNotes is null.
After all edits and comments, the problem is in:
#NSManaged var clinicNotes: String
It's optional in your Core Data model, but not in your class. Should be changed to:
#NSManaged var clinicNotes: String?
Here's similar problem where Imanou suggests mogenerator, which can handle it for you. It automatically generates two classes for each managed object. Human part is suitable for editing (not touched by mogenerator when updating your model) and machine is not suitable for editing (rewritten every time you do update your model). Human part inherits from machine part.
Whenever I'm working with Core Data I do use it. I strongly suggest it as well. You can also add it to build phase, so, it automatically update your machine classes when you're building your project.
When using this construction, you don't have to use ? as it is unwrapped for you.
try
if let clinic = receivedVisitDetails.clinicNotes {
cell.textLabel?.text = clinic
}