Posts

Showing posts with the label uitableview

Reference to a TableView Delegate Object within a Scene in Swift 4

Reference to a TableView Delegate Object within a Scene in Swift 4 I have a tableview in a SpriteKit scene. Using a tableview delegate method, I like to pass to another scene/ViewController, which cell was selected. There is only a single storyboard as this is entirely a SpriteKit game. //TableView inside Scene & Delegate Protocol: protocol gameSelectedDelegate { func theGameSelected(gameInt: Int) } class GamesTableView: UITableView, UITableViewDelegate,UITableViewDataSource { //Test Data var items: [String] = ["Player1", "Player2"] let defaults = UserDefaults.standard var gamesList = [Game]() var passedGame: Int? //instance of delegate var selectionDelegate: gameSelectedDelegate!` //GameScene to receive tableview data and delegate for my tableview class GamePlay: SKScene, gameSelectedDelegate { var backButton = SKLabelNode(fontNamed: "ArialRoundedMTBold") var score = SKLabelNode(fontNamed: "ArialRoundedMTBold") var passedGame = 0 //Not gett...

Why placeholder text jump upward little when first tap searchBar?

Image
Why placeholder text jump upward little when first tap searchBar? I put a searchBar in first cell in the UITableView (not in UITableView header!) : firstCell.contentView.addSubview(searchController.searchBar) and I canceled hide navigation bar when search happened : searchController.hidesNavigationBarDuringPresentation = false and full setup searchController code in below : func setupSearchController(){ //custom Search Results Controller let folderSearchVC = FolderSearchViewController() searchController = UISearchController(searchResultsController: folderSearchVC) //cancel hide NavigationBar searchController.hidesNavigationBarDuringPresentation = false searchController.searchResultsUpdater = folderSearchVC searchBar = searchController.searchBar searchBar.placeholder = "搜索习惯组" firstCell.contentView.addSubview(searchBar) } But when I first activate the searchBar,the placeholder text will jump upward a little,only for the first time (demo in...

iOS: If server database order changes, how to make my UITableView reflect it?

iOS: If server database order changes, how to make my UITableView reflect it? Currently, I have a UITableView and load data from my database to my UITableView like so. UITableView UITableView - (void)getData { // self.data is my UITableView data source self.data = [Database getNumbers]; [self.tableView reloadData]; } This works well for most part, however if the number order changes because of the server. It seems I have to call getData method again. getData For example, if the the current order is 1,2,3,4,5 but the server changes number order to 1,4,2,3,5 I will have to update my database and then call getData method. getData Is there a better solution? I hate having to retrieve the numbers from database all over again and reload the tableview. This seems like the best solution however and it does work. I hope this makes sense. Ultimatly I am trying to keep the numbers in order with the server. Your title mentions FMDB. You...

Slide to delete with similar design to iOS 10+ Notifications slide to delete in UITableViewCell

Image
Slide to delete with similar design to iOS 10+ Notifications slide to delete in UITableViewCell How can I make a tableviewcell's slide to delete look like the slide to delete for iOS notifications (fade in and don't touch edge of the screen). I will only have the delete button so I don't need multiple buttons. I would like it to delete upon a full swipe just like the notifications. Here's a photo of the wanted result with 2 buttons (I only want 1): The current code I have written only sets the editing style to delete. I have tried using UIContextualAction but I believe I can only set the style, background color, and/or image. UIContextualAction func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return true } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { print("delete") } } This is what it looks l...

search result not work went add tableviewcell

Image
search result not work went add tableviewcell Search bar is woking very well until I add custom tableview cell. It breaks when I search a keyword matching with a array. When I search wrong, it doesn't break. var filteredArray = [String]() var searchController = UISearchController() var result = UITableViewController() override func viewDidLoad() { super.viewDidLoad() searchController = UISearchController(searchResultsController: result) tableView.tableHeaderView = searchController.searchBar searchController.searchResultsUpdater = self result.tableView.delegate = self result.tableView.dataSource = self result.tableView.register(UITableView.self, forCellReuseIdentifier: "Cell") } //config seachbar func updateSearchResults(for searchController: UISearchController) { filteredArray = array.filter( { (array : String) -> Bool in if array.contains(searchController.searchBar.text!) { return true } else ...

Facebook native Ads are not clickable again in UITableView Cells after scroll

Facebook native Ads are not clickable again in UITableView Cells after scroll I have implemented facebook native Ads in UITableView, for first 1-2 times it clickable but when I scroll tableview and come again back to the same cell, now Ads are not clicking, I am using swift 3.2 Below is the cell implementation. let ad = adsManager.nextNativeAd let cell = self.tableHome.dequeueReusableCell(withIdentifier: "HomeAdsTableViewCell", for: indexPath) as! HomeAdsTableViewCell cell.message.text = ad?.body cell.title.text = ad?.title cell.callToActionButton.setTitle(ad?.callToAction, for: .normal) if let pic = ad?.coverImage { cell.postImage.setImageWithIndicator(imageUrl:pic.url.absoluteString) } ad?.registerView(forInteraction: cell.postView, with: self) cell.selectionStyle=UITableViewCellSelectionStyle.none return cell 2 Answers 2 First in your viewDidLoad() check that you add override func ...

Pushing NContactViewController results in black navigationbar. Why?

Pushing NContactViewController results in black navigationbar. Why? I have been trying to solve this problem for a while, so here is my question : I want to create an unknown contact with a given set of values as you may say: fileprivate func showUnknownContactViewController() { let aContact = CNMutableContact() let newEmail = CNLabeledValue(label: CNLabelWork, value: email! as NSString) aContact.emailAddresses.append(newEmail) let workPhone = CNLabeledValue(label: CNLabelWork, value: CNPhoneNumber(stringValue : phone!)) aContact.phoneNumbers.append(workPhone) let ucvc = CNContactViewController(forUnknownContact: aContact) ucvc.delegate = self ucvc.allowsEditing = true ucvc.allowsActions = true ucvc.alternateName = firstName! + " " + lastName! ucvc.title = "Company" ucvc.message = UserDefaults.standard.string(forKey: "company")! ucvc.contactStore = self.store //needed for editing/adding contacts? self...