IBOutlet Visible after successful login, Objective C - ios

So i have a tableView that shows some information that i parse from the web. I also have a DetailViewController that shows additional information about the cell that the user clicks on.
Now I'm using a TabBarViewController and on the last tab bar i want to have a login section. If the user is logged in he/she will be able to change the information stored in the DetailViewController (there will be some UIButtons and some UILabels the user will be able to push and insert some text to.)
I tried to search on the web just as the title for this question has but I didn't find anything at all. So please if you could provide me maybe a name for this technique so i can look it up or even links for tutorials would be better. Any tips and suggestions would also be great!
BTW I'm thinking about using NSKeyChains (maybe other suggestions here?)

So,
You have to link each element you want to show/hide in your UIViewController with an IBOutlet:
#interface YourViewController ()
#property (nonatomic, weak) IBOutlet UILabel *yourLabel;
#property (nonatomic, weak) IBOutlet UIButton *yourButton;
#end
And you can have a method to display/hide those elements depending if the user is logged or not, like this:
- (void)showOrHideButtonsDependingOnLoggedState()
{
BOOL logged = // some method to discover if he/she is logged
if (logged) {
_yourLabel.hidden = NO; // depending if you to show or hide
_yourLabel.hidden = YES;
} else {
_yourLabel.hidden = NO;
_yourLabel.hidden = YES;
}
}
and call it before your view appear or when the logged state changes.
If you have some confidential information about the user and want to have a secure place to store that, you are right about storing it inside the Keychain. There are a few libraries you can use to avoid the pain of store/loading it by your own. One of them is that: https://github.com/danielalves/NitroKeychain

You can use 2 containers in your storyboard. One would be the login view controller, the other one would be your DetailViewController.
Then you just have to hide the login view controller is the user is already logged in.
This tutorial might help you
Or you can also just present the login view controller modally so that the user is forced to login to acces the DetailViewController.
See Apple's reference

Related

Apple watch interface

I am designing apple watch application where i need to show top10 feed title and i have successfully shown it. in next step i have to add action event to tap which will redirect user to next screen but i am confused which controller to use here. i have to show all feeds in pagination format and then on click i have to show its detail view.
does anyone tried with this approach? i am using UIButton over there but its having text limitation so cant use it and for tableview it scroll verticaly where as i need horizantle scroll.
alph0x's answer is pretty useful. But you can also do another thing to perform what you are asking in case you only want that the action will do when push in a specific button of the row.
This second solution consists on create a class for the custom row with an IBAction
#import <WatchKit/WatchKit.h>
#interface MyRow : NSObject
// Methods
- (IBAction)buttonClick;
#end
And in the buttonClick method, you can specify the action as in the follow example using pushControllerWithName:context to go to a specific interface controller
#import "MyRow.h"
#implementation MyRow
- (IBAction)buttonClick {
[self goToInterface:#"feedInterface"];
}
- (void)goToInterface:(NSString *)interfaceName{
NSDictionary *contextToSend = [NSDictionary dictionaryWithObjectsAndKeys:#"FeedTitle", #"title",
#"lalala", #"secondValue",
#"lelele", #"thirdValue",
#"other value", #"other", nil];
[self pushControllerWithName:interfaceName context:contextToSend];
}
#end
You can send your row info through context. In that example I have decided to send a dictionary with some values.
In the interfaceName param you have to specify the Interface Controller Identifier that you can set in your storyboard. See the image below:
And tell to the XCode that your table row has the custom class MyRow
Note: don't forget to assign your button to the IBAction method ;)
If I understand, you need to have a table with 10 rows, and you need to be able to tap in one row, and view the details about the one you selected, if thats correct, you only need to use the Method from WKInterfaceTable "- (id)rowControllerAtIndex:(NSInteger)index", with this one (works like UITableView one with the delegate) you can handle every row action after being tapped.

Set up profileViewController UIImageView & UILabel based on different users

I am making an app at the moment but I am faced with an issue. I am new enough to the world of iOS development so please be patient. In my app a user registers by inputing data into cells in a tableView. e.g name, profile photo etc..
If registration is successful the user is then sent to their home page where I have a UIImageView and a UIlabel.
The issue
I am wondering how I can make sure that this UILabel and UIImageView are set according to the user. e.g when user A logs in or registers the UIImageView matches the image they used when registering and so on and so forth for userB, userC etc...
Any suggestions would be great and I hope I am clear in what I am trying to achieve?
Once the user press the loginButton Button in the resgisterViewController. You'll have to pass a NSString for your UILabel and an UIImage for you UIImageView in the MainViewController.
Follow this answer (Passing Data Forward) step-by-step on how to do that. You RegsiterViewController will be the ViewControllerA and MainViewController will be ViewControllerB in that answer.
You can create an initWithUser: method for instantiating your profileViewController, in which the User object has properties indicating the userName and imageName, for example. On viewDidLoad you assign these to your UIImageView and UILabel.
Fo reducing the confusion you can store the all data locally in some variable or dictionary and then you use the same. To use it on other view controllers just make those variables or dictionary globally accessible.

Persistence of cell values in a hierarchy of views with tables

I'm going to explain my scenario: I have a custom class whose properties are intended to get the information provided by the user through a form. This is the custom class:
#interface CustomClass : NSObject
#property NSInteger iD;
#property (strong, nonatomic) NSString *profilePicUrl;
#property (strong, nonatomic) NSString *email;
#property (strong, nonatomic) NSString *firstName;
#property (strong, nonatomic) NSString *lastName;
#property (strong, nonatomic) NSString *address;
#property NSInteger zipCode;
#property (strong, nonatomic) NSMutableArray *products;
#property BOOL isEnabled;
#end
The form consist of three views with an UITableView, and their respective view controllers are within a UINavigationController. This way, it is like a multi-step form: there is a first view requesting user input, then navigate to a second view requesting user input, then navigate to the third view displaying information before submitting the data provided. The "back" button of the navigation bar is enabled, so users could go back to a previous step to complete/change their inputs.
Cells of the tables are of different types, corresponding to the properties of the custom class I described: some of them have a text field (cells for entering first name and last name, for example), some others a switch ("isEnabled" property), and I have one cell with a button that displays an UIImagePickerController to take a picture (cell for profile picture).
I want to create an instance of my CustomClass and have its data completed at third step of the form to submit it. A part of the information is requested in the first view (profile picture, email, first and last name), and the rest is requested in the second view (address, zip code, products), so I'd need to pass the CustomClass object through the three view controllers of the navigation hierarchy.
My question is: how should I manage the persistence of the values in cells when the user enters them? Should I "bind" somehow the CustomClass properties to each corresponding cell? I'd want the user to be able to go fordward and back in the form and keep the data that she already entered. It looks like the values I type in text fields are retained and if I navigate from first view to second, and I go back to first again, the text field values are kept, but not the rest of the cells' content. And what if the app suddenly terminates and I donĀ“t want the user to enter again all the information? Note: my app has to support iOS 5.
What should be the best way to manage this scenario? Thanks!
You have to persist the info in your CustomClass. You could do this by writing it to a plain text file, a property list or use a database, or even use the NSUserDefaults infrastructure.
The save should occur immediately whenever data has been entered, for example in textField:didEndEditingand such callbacks. You would update the property of your CustomClass object and then persist it.

Can't make URL clickable in UITextView

I'm using Interface Builder to layout my app. I have a UITextView that contains some text, part of which is a URL that I'd like to make clickable (e.g. launches a browser). I've read up on how to do this and believe I'm doing it correctly, however while the URL appears blue/clickable, clicking it in the iPhone emulator doesn't work. Nothing happens.
My controller:
#interface FirstViewController : UIViewController <UISearchBarDelegate>
#property (nonatomic, retain) IBOutlet UITextView *review;
#end
In my implementation I #synthesize review; (and am able to manipulate the view's text, so don't think that's the issue).
In IB I have:
..then later when I go to set the text (and attempt to make URLs in the view clickable) I do:
self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.dataDetectorTypes = UIDataDetectorTypeLink;
...which displays something like:
...which really looks like it wants to work, however when clicking the URL nothing happens. What am I missing?
--UPDATE--
Tried adding self.review.editable = NO; in response to Dixit Patel's answer, but it didn't fix the issue:
self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.editable = NO;
self.review.dataDetectorTypes = UIDataDetectorTypeLink;
Check the "Selectable" and "Links" checkboxes in the textview Attributes Inspector:
The issue was that User Interaction Enabled wasn't checked at the bottom of the View section of IB's Attributes Inspector.

Using Two Views with One UIViewcontroller

I am using one simple UIViewController for my application which is not too complicated. It has two pages. On the first page I enter data in to text boxes to indicate user changeable data which will be handled on the second page.
#property (weak, nonatomic) IBOutlet UITextField *routeText;
When I am running my actions on the second page, I use a command like this to access what was typed in to the text box:
NSString *variable = [[NSString alloc]initWithFormat:#"%#",self.routeLabel.text];
self.consoleView.text = variable;
But the value is always (null). I am using the same TravelViewController.h/.m for all of the code. My question is: Is this not acceptable coding behavior to share it in this way or do I need to define the objects in a different way so the text can be shared between views?
Thanks for any help you could provide.
If it is a different view controller you need to pass the text from parent view controller to child using #property. Declare it in second class and when you are pushing from first screen to second, set this value in #property. After that you can use it in second screen using self.text.

Resources