Checkbox go to another view controller objective c - objective-c

I am trying to create a checkbox button, when the user click on that button it will check in and take him to another view controller. below is my checkbox code, can anyone help how can send the user to the other view controller?
Note I am using a storybored.
The header
IBOutlet UIButton *Checkbox;
BOOL checked;
(IBAction)CheckboxAction:(id)sender;
and here is the code:
- (void)viewDidLoad : (BOOL)animated
{NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
checked = [defaults boolForKey:#"boxIsChecked"];
[self checkTheBox];}
-(void) checkTheBox
{
if (!checked)
{[Checkbox setImage:[UIImage imageNamed:#"checkBox.png"] forState:UIControlStateNormal];}
else if (checked)
{[Checkbox setImage:[UIImage imageNamed:#"checkBoxMarked.png"] forState:UIControlStateNormal];}
}
- (IBAction)CheckboxAction:(id)sender
{NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (!checked)
{[Checkbox setImage:[UIImage imageNamed:#"checkBoxMarked.png"] forState:UIControlStateNormal];
checked = YES;
[defaults setBool:checked forKey:#"boxIsChecked"];}
else if (checked)
{[Checkbox setImage:[UIImage imageNamed:#"checkBox.png"] forState:UIControlStateNormal];
checked = NO;
[defaults setBool:checked forKey:#"boxIsChecked"];}
[defaults synchronize];
}

- (IBAction)CheckboxAction:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (!checked) {
[Checkbox setImage:[UIImage imageNamed:#"checkBoxMarked.png"] forState:UIControlStateNormal];
checked = YES;
[defaults setBool:checked forKey:#"boxIsChecked"];
}
else if (checked) {
[Checkbox setImage:[UIImage imageNamed:#"checkBox.png"] forState:UIControlStateNormal];
checked = NO;
[defaults setBool:checked forKey:#"boxIsChecked"];
}
[defaults synchronize];
// ADD THIS
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
YourViewController *yourVC = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:#"YourViewControllerIdentifier"];
[self.navigationController pushViewController:yourVC animated:YES];
}

Related

Switch Between 2 UIViewControllers in a NavigationBar Underneath

I have built a UIViewController to contain two other UIViewControllers. What I would like to do using a UISegment in the UINavigationBar is to switch between both views. When the user is finished they click on "Done" and it goes back to the RootViewController. I got this to work except the UIViewControllers take the size of the whole screen so the top portion is covered by the UINavigationBar. They don't adjust to the space under the UINavigationBar. I have been trying different techniques without success.
I have already tried in the ChildUIViewControllers without success
self.edgesForExtendedLayout = UIRectEdgeNone;
Here is my code:
RootViewController Calls the Container
ContainerController *controller = [[ContainerController alloc] init]
[self.navigationController pushViewController:controller animated:YES];
Container Code
- (void)viewDidLoad {
[super viewDidLoad];
UIViewController *vc = [self getCurrentViewController]; // Returns Current ViewController to Display
[self addChildViewController:vc];
vc.view.frame = self.view.bounds;
[self.view addSubview:vc.view];
self.currentViewController = vc;
}
-(UIViewController *)getCurrentViewController{
UIViewController *vc;
switch ([[NSUserDefaults standardUserDefaults] integerForKey:#"currentView"]) {
case kView1:{
vc = (ViewController1 *)[[ViewController1 alloc] init];
}break;
case kView2:{
vc = (ViewController2 *)[[ViewController2 alloc] init];
}break;
}
return vc;
}
- (void)segmentedControlIndexChanged:(id)sender{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:[NSNumber numberWithInt:[sender selectedSegmentIndex]] forKey:#"currentView"];
[userDefaults synchronize];
UIViewController *vc = [self getCurrentViewController];
[self addChildViewController:vc];
[self transitionFromViewController:self.currentViewController toViewController:vc duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
[self.currentViewController.view removeFromSuperview];
vc.view.frame = self.view.bounds;
[self.view addSubview:vc.view];
} completion:^(BOOL finished) {
[vc didMoveToParentViewController:self];
[self.currentViewController removeFromParentViewController];
self.currentViewController = vc;
}];
self.navigationItem.title = vc.title;
}
Anybody know what the problem is? Thanks.
I found a solution. The reason that the tableview was under the navigationbar was due to the translucence of the navigation bar. When I set this:
self.navigationController.navigationBar.translucent = NO;
The views remained under the navigation bar. There was still a black bar above the UITableView I fixed that problem by instead of using a UITableViewController I user a UIViewController and added a tableView. Here is some code to make cycle between the two views in the container uiviewcontroller:
- (void)viewDidLoad {
self.viewController1 = [[ViewController1 alloc] init];
self.viewController2= [[ViewController2 alloc] init];
switch ([[NSUserDefaults standardUserDefaults] integerForKey:#"dataView"]) {
case kDataView:{
self.viewController1.view.hidden=YES;
self.viewController2.view.hidden=NO;
}break;
case kChartView:{
self.viewController1.view.hidden=NO;
self.viewController2.view.hidden=YES;
}break;
}
[self.view addSubview:self.viewController1.view];
[self.view addSubview:self.viewController2.view];
}
- (void)segmentedControlIndexChanged:(id)sender{
if ([[NSUserDefaults standardUserDefaults] integerForKey:#"dataView"]!=[sender selectedSegmentIndex]){
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:[NSNumber numberWithInteger:[sender selectedSegmentIndex]] forKey:#"dataView"];
[userDefaults synchronize];
self.segmentedControl.selectedSegmentIndex=[[NSUserDefaults standardUserDefaults] integerForKey:#"dataView"];
switch (self.segmentedControl.selectedSegmentIndex) {
case kDataView:{
self.viewController1.view.hidden=YES;
self.viewController2.view.hidden=NO;
}break;
case kChartView:{
self.viewController1.view.hidden=NO;
self.viewController2.view.hidden=YES;
}break;
}
}
}

How to hide the Alert Box when the internet connectivity is back.?

I have a music player app in which I am checking for internet connectivity when the app is running. When the connectivity is gone, I am showing an alert message and stopping the song. In case if the connectivity is back, I am again playing the song without user doing anything in it, but the problem is I am unable to hide the alert when the song is played back again. Here is the code:
#import "FirstViewController.h"
CM_EXPORT const CMTime kCMTimeZero;
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize metadatas;
#synthesize toggleButton;
#synthesize slider;
#synthesize mpVolumeView = _mpVolumeView;
#synthesize viewVolume;
- (void)viewDidLoad
{
toggleIsOn=TRUE;
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:self.viewVolume.bounds] ;
[self.viewVolume addSubview:volumeView];
[volumeView sizeToFit];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(IBAction)playButtonPressed:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:TRUE forKey:#"FirstPlay"];
[defaults setBool:YES forKey:#"alertShown"];
if(toggleIsOn){
toggleIsOn=!toggleIsOn;
player = nil;
NSString *stringurl = #"";
stringurl = #"http://majestic.wavestreamer.com:6221/listen.pls";
NSURL *url = [NSURL URLWithString:stringurl];
asset = [AVURLAsset URLAssetWithURL:url options:nil];
playerItem = [AVPlayerItem playerItemWithAsset:asset];
player = [AVPlayer playerWithPlayerItem:playerItem];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[playerItem addObserver:self forKeyPath:#"timedMetadata" options:NSKeyValueObservingOptionNew context:nil];
[playerItem addObserver:self forKeyPath:#"status" options:NSKeyValueObservingOptionNew context:nil];
[player play];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:#selector(audioSessionInterrupted:) name:AVAudioSessionInterruptionNotification object:nil];
[self.toggleButton setImage:[UIImage imageNamed:#"reload.png"] forState:UIControlStateNormal];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}
else {
[self.toggleButton setImage:[UIImage imageNamed:#"playMusic.png"] forState:UIControlStateNormal];
self->player.rate=0.0;
toggleIsOn=!toggleIsOn;
}
}
- (void)audioSessionInterrupted:(NSNotification *)notification
{
NSNumber *interruptionType = [[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey];
NSNumber *interruptionOption = [[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey];
switch (interruptionType.unsignedIntegerValue) {
case AVAudioSessionInterruptionTypeBegan:{
// [self.toggleButton setImage:[UIImage imageNamed:#"playMusic.png"] forState:UIControlStateNormal];
// • Audio has stopped, already inactive
// • Change state of UI, etc., to reflect non-playing state
} break;
case AVAudioSessionInterruptionTypeEnded:{
// • Make session active
// • Update user interface
// • AVAudioSessionInterruptionOptionShouldResume option
if (interruptionOption.unsignedIntegerValue == AVAudioSessionInterruptionOptionShouldResume) {
// Here you should continue playback.
[player play];
}
} break;
default:
break;
}
}
- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)audioPlayer
{
[player pause];
}
-(void)audioRecorderEndInterruption:(AVAudioRecorder *)audioPlayer
{
[player play];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:TRUE forKey:#"alertShown"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReachable = [Reachability reachabilityForInternetConnection];
[internetReachable startNotifier];
// check if a pathway to a random host exists
hostReachable = [Reachability reachabilityWithHostName:#"www.apple.com"];
[hostReachable startNotifier];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
[playerItem removeObserver:self forKeyPath:keyPath];
if ([keyPath isEqualToString:#"status"]) {
AVPlayerItem *pItem = (AVPlayerItem *)object;
if (pItem.status == AVPlayerItemStatusReadyToPlay)
{
metadatas.text = #"";
}
}
if ([keyPath isEqualToString:#"timedMetadata"]) {
for (AVAssetTrack *track in playerItem.tracks) {
for (AVPlayerItemTrack *item in player.currentItem.tracks) {
if ([item.assetTrack.mediaType isEqual:AVMediaTypeAudio]) {
NSArray *meta = [playerItem timedMetadata];
for (AVMetadataItem *metaItem in meta) {
NSString *source = metaItem.stringValue;
metadatas.text = source;
}
}
}
}
}
[self.toggleButton setImage:[UIImage imageNamed:toggleIsOn ? #"playMusic.png" :#"stop.png"] forState:UIControlStateNormal];
}
-(IBAction)fbButtonPressed:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(#"%#%#",#"Failed to open url:",[url description]);
}
-(IBAction)inButtonPressed:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://www.linkedin.com"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(#"%#%#",#"Failed to open url:",[url description]);
}
-(IBAction)tweetButtonPressed:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://www.twitter.com"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(#"%#%#",#"Failed to open url:",[url description]);
}
-(IBAction) sliderChanged:(id)sender
{
}
-(void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
switch (internetStatus)
{
case NotReachable:
{
NSLog(#"The internet is down.");
NSLog(#"%d",[defaults boolForKey:#"alertShown"]);
BOOL isAlertShown = [defaults boolForKey:#"alertShown"];
if(isAlertShown)
{
[self showAlert];
}
break;
}
case ReachableViaWiFi:
{
NSLog(#"The internet is working via WIFI.");
BOOL isFirstTimePlayed = [defaults boolForKey:#"FirstPlay"];
if(isFirstTimePlayed)
{
[self playButtonPressed:nil];
}
break;
}
case ReachableViaWWAN:
{
NSLog(#"The internet is working via WWAN.");
[self playButtonPressed:nil];
break;
}
}
}
-(void)showAlert
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:FALSE forKey:#"alertShown"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Alert" message: #"You have lost data connectivity. Please wait while we try to establish the connection again." delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
#end
In your method showAlert, you have a reference to the UIAlertView object, alert. Simply save that reference in a property so that you can access it later.
#interface FirstViewController ()
#property (nonatomic, strong) UIAlertView* internetConnectivityAlertView;
#end
-(void)showAlert
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:FALSE forKey:#"alertShown"];
self.internetConnectivityAlertView = [[UIAlertView alloc] initWithTitle:#"Alert"
message:#"You have lost data connectivity. Please wait while we try to establish the connection again."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[self.internetConnectivityAlertView show];
}
When you do get internet connectivity, simply call
if(self.internetConnectivityAlertView)
{
[self.internetConnectivityAlertView dismissWithClickedButtonIndex:0 animated:YES];
self.internetConnectivityAlertView = nil;
}
to dismiss the alert.
See the API Documentation for UIAlertView.

Save the Hidden State of A UIButton

I have a UISwitch that on Value Change, hides or unhides some UIButtons with an if statement. I would like the hidden state of the UIButtons to be saved when I switch views or exit the app. I have tried using NSUserDefaults but it does not save, it just reverts back to the state I had originally set in the .storyboard
.m code:
- (IBAction)buttonHidden:(id)sender {
NSUserDefaults *Defaults = [NSUserDefaults standardUserDefaults];
[Defaults setBool:china.hidden forKey:ChinaChanged];
[Defaults setBool:japan.hidden forKey:JapanChanged];
[Defaults setBool:french.hidden forKey:FrenchChanged];
[Defaults setBool:spanish.hidden forKey:SpanishChanged];
[Defaults synchronize];
}
.m viewDidLoad code:
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *Defaults = [NSUserDefaults standardUserDefaults];
china.hidden = [Defaults boolForKey:ChinaChanged];
japan.hidden = [Defaults boolForKey:JapanChanged];
french.hidden = [Defaults boolForKey:FrenchChanged];
spanish.hidden = [Defaults boolForKey:SpanishChanged];
}
I do not know where I can connect the IBAction to make it work.
This is my if statement code for the UISwitch:
(IBAction)switchTheSwitch:(id)sender {
if (Languages.on) {
china.hidden = NO;
japan.hidden = NO;
french.hidden = NO;
spanish.hidden = NO;
}
else {
china.hidden = YES;
japan.hidden = YES;
french.hidden = YES;
spanish.hidden = YES;
}
}
Can anyone help me.
im not sure I follow but to me it seems all you lack is a call to buttonHidden so that defaults get actually saved
just do
-(IBAction)switchTheSwitch:(id)sender {
if (Languages.on) {
china.hidden = NO;
japan.hidden = NO;
french.hidden = NO;
spanish.hidden = NO;
}
else {
china.hidden = YES;
japan.hidden = YES;
french.hidden = YES;
spanish.hidden = YES;
}
[self buttonHidden:sender];
}

Facebook login not properly being recognized once returning to app

I'm having trouble implementing the Facebook SDK in an iOS project. I am trying to call it on a specific section of my app through a UIActionSheet. I am able to login to Facebook, but once redirected back to my app, the app does not register that it is logged in and can't execute any of its sharing functions.
I have followed the Facebook iOS Tutorial at https://developers.facebook.com/docs/mobile/ios/build/ to include adding "fbMY_APP_ID" in the project info but can't figure out why it won't recognize that I am logged in.
Here is the relevant header and method I am using. For convenience, I've removed items unrelated to Facebook implementation:
//Header
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import "MWFeedItem.h"
#import "FBConnect.h"
#interface DetailTableViewController : UITableViewController <UIAlertViewDelegate, UIActionSheetDelegate, UIApplicationDelegate, FBSessionDelegate>{
Facebook *facebook;
BOOL login;
}
#property (nonatomic, strong) Facebook *facebook;
#end
And the method:
// Method
#import "DetailTableViewController.h"
#import "NSString+HTML.h"
#import <Twitter/Twitter.h>
#implementation DetailTableViewController
#synthesize facebook;
//Navigation button on detail view does THIS:
- (void)navAction {
NSLog(#"Action sheet activated.");
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:#"Like this story?"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Email link"
otherButtonTitles:#"Share on Facebook", #"Share on Twitter", #"Open in Safari", nil];
[actionSheet showInView:[self.view window]];
}
-(void)actionSheet: (UIActionSheet *) actionSheet willDismissWithButtonIndex:(NSInteger) buttonIndex{
///////THIS SECTION DEFINES THE EMAIL SHARE FUNCTION/////
if (buttonIndex == 0) {
// MFMailComposeViewController implementation
}
///////THIS SECTION DEFINES THE FACEBOOK SHARE FUNCTION/////
else {
if (buttonIndex == 1) {
if (login == NO){
NSLog(#"No login detected");
UIAlertView *infoAlert = [[UIAlertView alloc]
initWithTitle:#"Login necessary"
message:#"You must first login to your Facebook account to use this feature."
delegate:self
cancelButtonTitle:#"Login"
otherButtonTitles:#"Cancel", nil];
[infoAlert show];
}else {
if (login == YES){
NSLog(#"Login detected.");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:#"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:#"FBExpirationKey"];
[defaults synchronize];
//APPLY LOGIN ACTION HERE. Waiting until I can make the system run the NSLog above. So far, the login is not being correctly recorded.
}
}
}
///////THIS SECTION DEFINES THE TWITTER SHARE FUNCTION/////
else {
if (buttonIndex == 2) {
//Twitter implementation here
}
///////THIS SECTION DEFINES THE SAFARI FUNCTION/////
else{
if (buttonIndex == 3){
//Safari implementation here
}
}
}
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// CALL TO FACEBOOK HERE
facebook = [[Facebook alloc] initWithAppId:#"MY_APP_ID" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"] && [defaults objectForKey:#"FBExpirationDateKey"]){
facebook.accessToken = [defaults objectForKey:#"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:#"FBExpirationDateKey"];
}
if (![facebook isSessionValid]){
NSLog(#"Reached isSessionValid evaluation.");
[facebook authorize:nil];
}
}
else if (buttonIndex == 1)
{
NSLog(#"Pressed cancel button");
}
}
// THIS METHOD SUPPORTS IOS PRE 4.2
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
return [facebook handleOpenURL:url];
}
// THIS METHOD SUPPORTS IOS AFTER 4.2
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
return [facebook handleOpenURL:url];
}
////////////////////////////////////////////
- (void)fbDidNotLogin:(BOOL)cancelled{
}
- (void)fbDidExtendToken:(NSString*)accessToken
expiresAt:(NSDate*)expiresAt{
}
- (void)fbDidLogout{
}
- (void)fbSessionInvalidated{
}
- (void) fbDidLogin {
NSLog(#"Logged in with Facebook credentials");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:#"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:#"FBExpirationKey"];
[defaults synchronize];
//APPLY LOGIN ACTION HERE. Waiting until I can make the system run the NSLog above. So far, the login is not being correctly recorded.
}
Additional info:
I've also tried adding the openURL portions to the main app delegate file but had the same results.
Try this code in your project. I had a same issues which you have. Now my code is working perfect. Call your sharing method in your fbDidLogin method too. Dont forget to change your App id in code and also .plist File.
-(void)buttonPressed:(id)sender{
facebook = [[Facebook alloc] initWithAppId:#"YOUR_APP_ID" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"] && [defaults objectForKey:#"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:#"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:#"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
[facebook authorize:nil];
}else{
[self postWall];
}
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:#"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:#"FBExpirationDateKey"];
[defaults synchronize];
[self postWall];
}
-(void)postWall{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"https://developers.facebook.com/docs/reference/dialogs/",#"link",
#"http://fbrell.com/f8.jpg",#"picture",
#"Facebook Dialogs",#"name",
#"Reference Documentation",#"caption",
#"Using Dialogs to interact with users.",#"description",
#"Facebook Dialogs are so easy!",#"message",
nil];
[[self facebook] dialog:#"feed" andParams:params andDelegate:self];
}
This could be related to some deprecated Facebook API methods. See this post for possible help as well: related question

viewDidLoad not running when expected

I have the following code in my viewDidLoad to change an image:
- (void)viewDidLoad
{
[super viewDidLoad];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"colour"] == nil) {
[defaults setObject:#"Red" forKey:#"colour"];
[defaults setInteger:0 forKey:#"colourIndex"];
[defaults synchronize];
}
[background setImage:[UIImage imageNamed:[defaults objectForKey:#"colour"]]];
NSLog(#"%#", [defaults objectForKey:#"colour"]);
// Logs "Blue"
}
When I open my flipside view in the iPhone Simulator and then go back to my original view, the result of the NSLog doesn't change and the image doesn't change. Why is this happening?
Move this code to viewWillAppear. viewDidLoad is not called every time the view is presented.
This link provides a good explanation.
UIViewController viewDidLoad vs. viewWillAppear: What is the proper division of labor?