Set up profileViewController UIImageView & UILabel based on different users - ios

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.

Related

Wanting to use a UIViewController flow for two separate cases

I have two UIViewControllers - one that handles the camera, and the other that allows the taken picture/video to be edited. These two go hand-in-hand to form part of a picture-taking flow within my app. I want to use these two controllers in two different circumstances:
The first is that after the image has been edited, it's passed to another UIViewController to add some additional info to the image.
The second is that after the image has been edited, it should return that image to the UIViewController that initiated the camera view flow.
How should I be telling my UIViewController flow which UIViewController to send the edited image to? Do I need to pass an enum variable along the flow or is there a better way?
I think add a complete handler to the UIViewController is a good way. You may send the complete closure to your UIViewController. Enum is good too.

Changing the initial load screen at different conditions

I have 2 views as shown in the following diagram. First View is a ViewController and the 2nd is a TableViewController.
After the user installs and runs the app for the first time he/she will see View number (1) (as shown in the image). Thereafter when the user opens the application for the 2nd time he/she is suppose to see the second (2) viewcontroller.
How am i to program this ?
NB: For example in Viber the user will first see the Enter the phone number view controller, and once the user successfully logins he'll directly see the all contacts view. I am looking to implement the same functionality. Can someone tell me how this is done ?
Solution i came across is when the user successffully logins, i set a NSUserDefaults.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:loginSuccess forKey:#"yes"];
[defaults synchronize];
Thereafter i check if this is set in the didFinishLaunchingWithOptions method. Is this the correct way to do this ?
Using NSUserDefaults is a great way to keep track of which view to show. To actually show the correct view you make the UITableViewController the root view controller for your app. Then in its viewDidLoad you check the value you stored in NSUserDefaults. If you need to display the one-time-only controller then you can simply use presentViewController:vc animated: NO. This will make it appear to the user that they started at the one-time-only controller, but for the rest of time you will have the "normal" flow work as expected.
Check for the second call by using NSUserDefaults. Upon start check for a value for any key. When that is null then it is the first time after installation, that the app is executed. After that store something with the very key.
You can do the check in your application delegate (in application didLodWithOptions) and then show either this or that.
Or you perform the check in viewDidLoad in your tableview controller. You can simply push to the other view (or display it modally). This is quite convenient when you want the user to return to the tableview as soon as his introduction is over. Then simply discard the other view ontop of the tableview.

IBOutlet Visible after successful login, Objective C

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

switch function to make page available

I've searched through the forums and wasn't able to find anything similar to this question. It's my first time posting so please let me know if I need to add anymore information and I'll try my best!
I'm exploring Xcode and building an app for iOS 7 on an iPhone. I'm using a hypothetical purpose for the app just to see if I can learn how to build the thing (it's a booking system for taxis). It's a tabbed application (I have three tabs at the bottom corresponding to three different screens of the app, one is rates which displays a scrollable image of rates, one is a booking system that sends an email with information taken from text fields, and one is a settings page)
My questions is as follows:
On the booking page, I'd like to have a switch that either enables or disables user entry into additional text fields (it's actually for the option to book a 'return' journey, so the user can add in extra information for the return booking).
I have my page set up with the first text fields in place, but I can't for the life of me figure out or find anywhere about how to make this switch enable entry into the additional text fields. Ideally I'd like them to be greyed out and disabled if the switch is off, and enabled if the switch is on.
Any help on the matter would be much appreciated!
Thanks.
edit:I'm also doing this with storyboard, wasn't sure if this made a difference!
You can use UISwitch and UITextField for this. UITextField has a property called enabled that controls whether the user can interact with it.
First you need to create an IBOutlet for your UITextField in storyboard by control-dragging it to respective #interface definition in your header file. Then you need to create an IBAction for your UISwitch, again by control-dragging it to #interface (choosing 'Action' for 'Connection' and 'changed' for 'Event').
Finally implement the newly generated method like this:
#implementation ViewController
-(void)mySwitchChanged:(id)sender
{
UISwitch *mySwitch=(UISwitch *)sender;
myTextField.enabled=[mySwitch isOn];
}
.
.

How to Get the value(label) from the TextField inside the custom cell of a table View to post on te URL

I want my iOS app to pass to a URL the text the user types. The relevant code is pasted below. WHen I run the app, the text does not get assigned any value. It stays as null.
I am new to iOS programming and am probably missing something obvious here. Any help/pointers will be appreciated.
Mac OS version : 10.6.8 (64 bit)
Xcode version : 3.2.3
In the snapshop.. "I have created a Table View and placed custom cell inside each row of a table. TextField is inside the custom cell view. Post is a button next to the textField which is a done Button. If I click that button, the text we are entering in the textField should post on URL which i have specified in my code snippet."
NOTE: The text is like a comment and posting this comment that should post on particular image in that cell.
I have copied the code snippet below. I have also attached an image to explain.
-(IBAction)postAction:(id)sender
{
int index=[sender tag];
homecell *cell = [[homecell alloc] init];
UITextField *txt_c =(UITextField *)[cell.txt_comment viewWithTag:index];
NSLog(#"jj %#",txt_c);
gen_data *ut1=[[gen_data alloc]init];
gen_data *ut=[gen_data getInstance];
}
I assume that you have created that view using the interface builder, probably all you need is to connect that textfield as an IBOutlet and access the value.
IBOutlet is the key word here, search for it and you will find really fast the way to do it.
Check this link.
You should get some basics of iOS programming first.
Why are you creating a totally new custom cell that is irrelevant to your UITableView? When you create it that way, it's a totally new UITableViewCell.
You should connect it to it first, get its NSIndexPath and then operate with it and do what you want.
BTW, if you want to see the text of UITextfield you should NSLog myTextField.text
And you could easily write viewWithTag:sender.tag, no need to create an extra ivar here

Resources