-1

I'm trying to add the slide to refresh feature to my app's table. I'm currently following the guide on YouTube found here and my app is crashing with a SIGABRT error when initializing the slide to refresh.

My Code:

 // outlet - table view
@IBOutlet weak var myTableView: UITableView!


// outet - activity indicator
@IBOutlet weak var spinner: UIActivityIndicatorView!


// outlet - barbutton
@IBOutlet weak var menuButton: UIBarButtonItem!

// slide to refresh

let refreshControl: UIRefreshControl = UIRefreshControl()

// xml parser
var myParser: NSXMLParser = NSXMLParser()

// rss records
var rssRecordList : [RssRecord] = [RssRecord]()
var rssRecord : RssRecord?
var isTagFound = [ "item": false , "title":false, "pubDate": false ,"link":false]



// MARK - View functions

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    if self.revealViewController() != nil {
        menuButton.target = self.revealViewController()
        menuButton.action = "revealToggle:"
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }


    // pull to refresh
    refreshControl.addTarget(self, action: "uiRefreshControlAction:", forControlEvents:  UIControlEvents.ValueChanged)
    self.myTableView.addSubview(refreshControl);


    func uiRefreshControlAction() {
        self.myTableView.reloadData()
    }

    // set tableview delegate
    self.myTableView.dataSource = self
    self.myTableView.delegate = self
}

If anyone could tell me what I'm doing wrong that would be great. I'm new to Xcode and this is my first app, so if I did something totally wrong sorry for that.

Gabe Zimbric
  • 47
  • 1
  • 6

2 Answers2

1

In your code you have written

 // pull to refresh
refreshControl.addTarget(self, action: "uiRefreshControlAction:", forControlEvents:  UIControlEvents.ValueChanged)
self.myTableView.addSubview(refreshControl);

Change that to

 // pull to refresh
refreshControl.addTarget(self, action: "uiRefreshControlAction", forControlEvents:  UIControlEvents.ValueChanged)
self.myTableView.addSubview(refreshControl);

as you are not passing any parameters in that function but you have added ':' in the action name which indicate you are going to have parameter in the function

So your full new code will be like this

// MARK - View functions

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    if self.revealViewController() != nil {
        menuButton.target = self.revealViewController()
        menuButton.action = "revealToggle:"
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }

    // pull to refresh
    refreshControl.addTarget(self, action: "uiRefreshControlAction", forControlEvents:  UIControlEvents.ValueChanged)
    self.myTableView.addSubview(refreshControl);

    // set tableview delegate
    self.myTableView.dataSource = self
    self.myTableView.delegate = self
}  

func uiRefreshControlAction() {
     self.myTableView.reloadData()
}
HardikDG
  • 5,892
  • 2
  • 26
  • 55
0

You cannot just go putting func uiRefreshControlAction just anywhere you feel like. Positions of things in your code have a meaning. Learn Swift. Learn how it works.

Meanwhile I'll just tell you the answer on this one. Change this structure:

override func viewDidLoad() {
    super.viewDidLoad()
    // ...
    func uiRefreshControlAction() {
        self.myTableView.reloadData()
    }
    // ...
}

To this:

override func viewDidLoad() {
    super.viewDidLoad()
    // ...
}
func uiRefreshControlAction() {
    self.myTableView.reloadData()
}

Then change this:

action: "uiRefreshControlAction:"

to this:

action: "uiRefreshControlAction"

Finally, update to Xcode 7.3 where this sort of mistake will be impossible for you to make!

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I should most likely learn this before I continue. Thanks for the input, but changing that didn't work, after changing this my RSS feed didn't load and the slide to refresh was gone. – Gabe Zimbric Mar 23 '16 at 03:25
  • did you make other things same as your code ? just remove the function from 'viewDidLoad' and place it outside – HardikDG Mar 23 '16 at 03:28
  • @matt After reading your edit there isn't any more errors. When I'm done tonight I'll update for sure. Only thing now is that the spinner won't stop. Is it because there is no response from the RSS feed or do I need to do something within the swift file for it to stop after refreshing the feed? – Gabe Zimbric Mar 23 '16 at 03:35
  • @GabeZimbric UIRefreshControl has two methods which you can use to start/stop loading indicator ` - beginRefreshing - endRefreshing`, this may help you – HardikDG Mar 23 '16 at 03:39
  • @Pyro That fixed it by adding `self.refreshControl.endRefreshing()` to `func uiRefreshControlAction()` Thanks! – Gabe Zimbric Mar 23 '16 at 03:41