Displaying Skills Feedback on SUSI iOS
SUSI allows the user to rate the SUSI Skills with the five-star rating system. SUSI offer a good feedback system where the user can post feedback to any skill by using iOS, Android, and Web clients. In Skill Detail, there is a skill feedback text field where the user can write feedback about SUSI Skill. We display the users posted feedbacks on Skill Detail screen. In this post, we will see how the displaying skills feedback feature implemented on SUSI iOS. Implementation - We are displaying three feedback on Skill Detail screen, to see all feedback, there is a “See All Review” option, by clicking user is directed to a new screen where he/she can see all feedback related to particular skill. We use the endpoint below for getting skill feedback from server side – https://api.susi.ai/cms/getSkillFeedback.json With the following params: Model Group Language Skill Name The API endpoint above return the all the feedback array related to particular susi skill. We store feedbacks in an array of Feedback object, which holds three value: Feedback String - Feedback string posted by the user Email - Email address of feedback poster user Time Stamp - Time of posting feedback class Feedback: NSObject { var feedbackString: String = "" var email: String = "" var timeStamp: String = "" ... } To display feedbacks, we are using UITableView with two prototype cells, one for feedbacks and one for “See All Review” option. There can be different cases eg. when the total number of feedback for skill is less than three or three. When the feedback count is three or less than three, there is no need to show “See All Review” option. Also, tableView height is different for different feedback count. For varying tableView height, we have created an outlet for tableView height constraints and vary accordingly. @IBOutlet weak var feedbackTableHeighConstraint: NSLayoutConstraint! Now, let’s see how the number of cells, height for cells and different cells presented according to feedback count with UITableViewDelegate and UITableViewDataSource methods. Handling number of tableView rows - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { guard let feedbacks = feedbacks, feedbacks.count > 0 else { feedbackTableHeighConstraint.constant = 0.0 return 0 } if feedbacks.count < 4 { feedbackTableHeighConstraint.constant = CGFloat(72 * feedbacks.count) return feedbacks.count } else { feedbackTableHeighConstraint.constant = 260.0 return 4 } } Where feedbacks is the array of Feedback object which holds the feedbacks we are getting from the server side for a skill. var feedbacks: [Feedback]? In the above method, we see that how we are handling the number of cells case. Now let’s see how to handle which cells to be present on basis of the number of cells case - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { guard let feedbacks = feedbacks, feedbacks.count > 0 else { feedbackTableHeighConstraint.constant = 0.0 return UITableViewCell() } if feedbacks.count < 4 { if let cell = tableView.dequeueReusableCell(withIdentifier: "feedbackDisplayCell", for: indexPath) as? FeedbackDisplayCell { cell.feedback = feedbacks[indexPath.row - Int(indexPath.row/2)] return cell } } else…
