신속한 답변이 필요합니다. 기본적으로, 나는 상쾌하게하기위한 두 가지 질문이있다. 코드가 너무 길어서 보지 못한다고 생각하면 이것이 내가하려는 것입니다. 하나는 tableview 셀 중 하나에서 삭제 버튼을 클릭 한 후 tableview를 새로 고치는 것입니다. 나는 refreshcontrol을 시도했다, 그것은 작동하지 않았다. 그리고 그것이 내가 원했던 것이 아니었다. 그러나 그들을 가지고있는 것은 멋질 것이다. 내 다른 질문은 단추를 클릭하여보기 컨트롤러를 새로 고치는 방법입니다. 여기 코드가 있습니다. 있는 UITableViewCell {테이블 뷰 셀을 삭제하고 뷰 컨트롤러를 새로 고친 후 테이블 뷰 새로 고침
@IBOutlet weak var deleteBtn: UIButton!
@IBOutlet weak var postImg: UIImageView!
@IBOutlet weak var category: UILabel!
@IBOutlet weak var location: UILabel!
@IBOutlet weak var title: UILabel!
@IBOutlet weak var price: UILabel!
var prices = String()
var notes = String()
var comments = String()
var locations = String()
var categories = String()
var school = String()
var username = String()
var date = String()
@IBAction func deleteAction(sender: AnyObject) {
let request = NSMutableURLRequest(URL: NSURL(string: "http://www.percyteng.com/orbit/deletePost.php")!)
request.HTTPMethod = "POST"
let postString = "name=\(username)&location=\(locations)&price=\(prices)¬es=\(notes)&school=\(school)&category=\(categories)"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
print("error=\(error)")
return
}
print("response = \(response)")
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("responseString = \(responseString)")
}
task.resume(); NSNotificationCenter.defaultCenter().postNotificationName("NotificationIdentifier", object: nil)
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated:animated)
}
}
그리고 내가 다른 클래스의 데이터를 다시로드 할있는 tableview :
override func viewDidLoad() {
super.viewDidLoad()
username = tempUser.username
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
get{(value) in
self.values = value
for ele in self.values{
if self.username != ele["username"] as! String{
}
}
}
self.tableView.reloadData()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(serviceBoard.methodhandlingTheNotificationEvent), name:"NotificationIdentifier", object: nil)
}
func methodhandlingTheNotificationEvent(){
tableView.reloadData()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (self.resultSearchController.active && resultSearchController.searchBar.text != "") {
return self.filteredTableData.count
}
else {
return values.count
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as!postCell
let maindata = values[values.count-1-indexPath.row]
if (self.resultSearchController.active && resultSearchController.searchBar.text != "") {
// if (filteredTableData[indexPath.row].rangeOfString("###") == nil){
cell.postImg.image = UIImage(named:"tile_services")
cell.title.text = filteredTableData[indexPath.row]
cell.category.text = "SERVICES"
var price = String()
for i in values{
if (i["title"] as? String)! == filteredTableData[indexPath.row]{
price = (i["price"] as? String)!
cell.categories = "Services"
cell.username = i["username"] as! String
cell.prices = i["price"] as! String
cell.notes = i["notes"] as! String
cell.school = i["school"] as! String
}
}
cell.price.text = price
return cell
}
else {
if maindata["username"] as! String != username && username != "admin"{
cell.deleteBtn.hidden = true
}
else{
cell.categories = "Services"
cell.username = maindata["username"] as! String
cell.prices = maindata["price"] as! String
cell.notes = maindata["notes"] as! String
cell.school = maindata["school"] as! String
}
cell.postImg.image = UIImage(named:"tile_services")
cell.title.text = maindata["title"] as? String
cell.category.text = "SERVICES"
cell.price.text = maindata["price"] as? String
return cell
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("showPostT") as! showPostT
self.addChildViewController(popOverVC)
popOverVC.view.frame = self.view.frame
self.view.addSubview(popOverVC.view)
popOverVC.didMoveToParentViewController(self)
if (self.resultSearchController.active && resultSearchController.searchBar.text != "") {
for i in values{
if (i["title"] as? String)! == filteredTableData[indexPath.row]{
popOverVC.type.text = "SERVICE"
popOverVC.typeImg.image = UIImage(named:"tile_services")
popOverVC.item.text = "Service: \(i["title"] as! String)"
popOverVC.price.text = "Price: \(i["price"] as! String)"
popOverVC.notes.text = "Notes: \(i["notes"] as! String)"
popOverVC.comments.text = i["comments"] as? String
popOverVC.postUser.text = i["username"] as! String
popOverVC.notesStr = i["notes"] as! String
popOverVC.category = "service"
popOverVC.pricesStr = i["price"] as! String
if username == popOverVC.postUser.text!{
popOverVC.composeBtn.hidden = true
}
}
}
}
else{
let maindata = values[values.count-1-indexPath.row]
popOverVC.type.text = "SERVICE"
popOverVC.typeImg.image = UIImage(named:"tile_services")
popOverVC.item.text = "Service: \(maindata["title"] as! String)"
popOverVC.price.text = "Price: \(maindata["price"] as! String)"
popOverVC.notes.text = "Notes: \(maindata["notes"] as! String)"
popOverVC.comments.text = maindata["comments"] as? String
popOverVC.postUser.text = maindata["username"] as! String
popOverVC.notesStr = maindata["notes"] as! String
popOverVC.category = "service"
popOverVC.pricesStr = maindata["price"] as! String
if username == popOverVC.postUser.text!{
popOverVC.composeBtn.hidden = true
}
}
}
나는 '돈
삭제 버튼 내 사용자 정의 셀 클래스 클래스 postCell의 내부 내 두 번째 질문에 대한 코드가 필요하다고 생각하면 단순히보기 컨트롤러를 새로 고치는 방법을 알고 싶을뿐입니다. 현재 컨트롤러를 닫고 다시 열려고했지만 분명히 작동하지 않습니다.
여러분이 궁금한 점이 있으면 도와 주시면 감사하겠습니다.
감사합니다.
아무것도를하지 않았다 때 어떻게 것 해당 작업 내에서 tableview를 참조 할 수 있습니까? 사용자 정의 셀에 테이블 뷰가 정의되어 있지 않습니다. –
https://en.wikipedia.org/wiki/Observer_pattern, NSNotificationCenter, KeyValue 관찰 또는 ReactivePrograming (리 액티브 키트) https : // github에 익숙해지기를 권합니다. .com/ReactiveKit/ReactiveKit –
그래서 사용자 정의 셀의 삭제 단추를 클릭하여 사용자 정의 셀이 포함 된 테이블 뷰인 주체에 알리는 신호를 알림 센터에 보냅니다. 알림 코드를 공유 하시겠습니까? Thx –