I've added the following code to my iOS project in XCode. It allows me to add multiple buttons to my UINavigation Controller - the items show fine in the app but when I press the 'Refresh' or 'Back' button the app crashes
What I'm trying to do is create 3 buttons - Refresh, GoBack and GoForward.
The error Im getting says Undeclared selector 'refresh'
// Create the refresh, fixed-space (optional), and profile buttons.
UIBarButtonItem *refreshBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
// // Optional: if you want to add space between the refresh & profile buttons
// UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
// fixedSpaceBarButtonItem.width = 12;
UIBarButtonItem *profileBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(goToProfile)];
profileBarButtonItem.style = UIBarButtonItemStyleBordered;
self.navigationItem.rightBarButtonItems = @[profileBarButtonItem, /* fixedSpaceBarButtonItem, */ refreshBarButtonItem];
Please follow the Link
Will be add more buttons in navigation bar
Check the declaration/definition of your refresh
method.
As per your code action:@selector(refresh:);
the refresh
method should have atleast one argument.
If your definition of refresh
method has not arguments then it should be like action:@selector(refresh);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.