UITableViewCellStyle - objective-c

I would like to create a table like the iPhone (calls) which are displayed three labels.
UITableViewCellStyleSubTitle displays only two options as well as UITableViewCellStyleSubValue1.
Do I have to manually create it?
Thanks.
/ / English Google

A third place to put something is the accessoryView, which shows up to the right of the cell.
The best way to have full control over a cell is to make a custom UITableViewCell. An example.

Yes, you have to manually create it. Watch this YouTube video for a tutorial.
Also, next time you ask a question, provide a more descriptive title, and you will likely get more views and answers.

As Peter DeWeese was saying you have to make a custom UITableViewCell.
Let me point out that since iOS 6 this is the only correct way to do it.
Make a subclass UITableViewCell.
In the initializer (.m file) you can rewrite the style that is given when the super class is called.
code example:
(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:--------UITableViewCellStyleSubtitle------- reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
Go to your TableViewController and registrate that cell in the viewDidLoad method.
[self.tableView registerClass:[---------FriendCell---------- class] forCellReuseIdentifier:#"vriendCel"];
//And if someone would help me out to put my code properly, can't seem to fix it. :)

Related

Know What UINavigationController the User is Inside UITabBarController

I have a UITabBarController that has 3 UINavigationControllers in my AppDelegate and I want to know how to determine the active UINavigationController where the user is. How can I determine this?
UITabBarController has a property called selectedViewController. Just check this for the appropriate value (e.g. by checking its class or a tag of its main view).
I figured it out on my own.
I just used this code to make my code work. It may seem a bit far from my original question but this made it to work as I just simply want to display my custom notification view on my current view.
if (self.tabBarController.selectedIndex == 0)
{
[self displayNotificationWhenOnline:self.navController1.visibleViewController.view];
}
else if (self.tabBarController.selectedIndex == 1)
{
[self displayNotificationWhenOnline:self.navController2.visibleViewController.view];
}
You can get perticuler view controller using this code,
[(UINavigationController*)[[(AppDelegate*)[[UIApplication sharedApplication]delegate] tabBarController] selectedViewController]visibleViewController]

Understanding Objective-C Overwrite Code

Disclaimer: The program I wrote works. I just need help understanding it.
Today I just started learning XCode and Objective-C. I have tons of experience with Java and I must admit this is very different. I'm currently following a book that has us dealing with two scenes in our story board. The Main View Controller Scene and the Flipside View Controller Scene.
In the main scene I have one label outlet that says Hello World. It's name is label. In the flipside scene I have a text outlet. When the user flips from the flipside scene to the main scene the text in the text outlet is applied to the label outlet. So if I type in Hello StackOverflow in the flipside, and then flip it I will see Hello StackOverflow in the main scene.
We did this by going to the method that controls the flip and is in the main scene .m class and added this code.
self.label.text = controller.labelText.text;
Can anyone explain this code please? I understand that label and labelText are my names. And text is looking for the text. But I have no idea where self and controller came from and it is not explained in the book. Thank you.
EDIT
Here is the full code with the function that has controller in the function heading. I don't get what is going on in this method. Any explanation would be great.
- (void)flipsideViewControllerDidFinish:(HWFlipsideViewController *)controller
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
[self dismissViewControllerAnimated:YES completion:nil];
}
else
{
[self.flipsidePopoverController dismissPopoverAnimated:YES];
self.flipsidePopoverController = nil;
}
self.label.text = controller.labelText.text;
}
self is the java this pointer and therefore points to your object
text is a property and would be getText()
so self.label.text is this.getLabel().getText() BUT
as it sets text=something it is setText!
=> java-bean style getter and setter
controller is likely a local variable.. PASSED to the method as an argument
OR it is a member variable on the object of the this instance
so it'd be
this.getLabel().setText(controller.getLabelText().getText());
this = the object you're in and that the main view I think
controller is the flipview
the 'overwrite' is setting the String of our label to the Controller's textfield string
You described, that you are in the context, where the flip is controlled. So the instance of the second controller (named controller) must be available there. So you may refer to it.
self is, as Xono stated in the comment already the pointer to the current object like this in java.

NSTextField set cursor

Okay so I feel like there's something obvious I'm missing in this question. I've used makeFirstResponder throughout my code to move from textField 1 to 2, 2 to 3, etc. That seems to work as I want it to, yet when the new view is loaded, I want the cursor to be in textField1, and yet the following code does not place the cursor in textField1 upon load.
- (void) awakeFromNib{
[[[self view] window] makeFirstResponder:textField1];
}
I also tried setInitialFirstResponder, and that didn't have any effect either (I don't even think that would be right.) So, is it because it is in the awakeFromNib method? Can anyone tell me what I'm missing? Thanks in advance.
EDIT - My solution was differed slightly from the accepted answer so I thought I'd post my implementation. Because the view I wanted to set the first responder for was a subview added later (think the second screen of an application wizard), I simply added a setCursorToFirstTextField method:
- (void) setCursorToFirstTextField {
[[[self view] window] makeFirstResponder:textField1];
}
And made sure to call it after I had added the subview to the custom view on the original window.
Yes, you're right about the problem being the location of the method in awakeFromNib. If you log [self.view window] in your awakeFromNib, you'll see that it's NULL. I don't know how exactly you have things set up, but I'm guessing (if this relates to your WizardController question) that you're doing an alloc initWithNibName:bundle: in another class to create your view controller and then adding that controller's view to the view hierarchy. If you throw some logs in there, it will show you that awakeFromNib in the controller class is called after the alloc init, but before the view is added as a subview, so there is no window at that time. The way I got around this problem was to create a setup method in the view controller class (with the makeFirstResponder code in it), and call it from the class where you create the controller after you add it as a subview.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.wizard = [[WizardController alloc] initWithNibName:#"WizardController" bundle:nil];
[self.window.contentView addSubview:wizard.view];
[self.wizard doSetup];
}

Stop UIPopover from dismissing automatically part II

Sorry I previously posted a question here, but The answers I got didn't work (probably my fault).
Basically, I want to stop a UIPopover from dismissing automatically. I got to this piece of code:
- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
which I put in, but it doesn't seem to have any effect. Is there anything else I should add?
am I putting it in the right place (I was putting it in the vc.m of the view that has the popover within it)?
Thanks Very Much,
Luke
Check to make sure the UIPopover delegate is set. You can do this in code by setting the popover instance variable:
aPopover.delegate = self;

Keyboard not show onload

I want the keyboad show automatically onload, but it did not work as i expect
here is the code i use:
- (void)viewDidLoad {
[super viewDidLoad];
[seachBar2 setDelegate:self];
}
- (BOOL)Searchbar2ShouldReturn:(UISearchBar *)searchBar2 {
[searchBar2 becomeFirstResponder];
return YES;
}
Coud somebody will point me how to fix this
thank you somuch
- (void)viewDidLoad {
[super viewDidLoad];
[seachBar2 setDelegate:self];
[seachBar2 becomeFirstResponder];
}
Just came across this, and it helped but the answers are vague.
All you need to do now in iOS 5 is make an outlet connection to your object (for example a UITextField) and then in viewDidLoad method type;
[myTextField becomeFirstResponder];
or for your search bar
[searchBar2 becomeFirstResponder];
Make sure searchBar2 in your code points (IBOutlet) to the searchBar in the Interaface Builder.
in your code:
IBOutlet UISearchBar *searchBar2;
In IB:
goto the search bar's Connections Inspector (apple-2) and drag the Referencing Outlet to File Owner and select searchBar2
Hope this helps.
You do need to override viewDidAppear:, and verify it's actually being called (put a breakpoint or an NSLog() statement in there). You should also determine the language you're coding in (it's Objective C).
Your -Searchbar2ShouldReturn: method will never be called by the system. I think you may need to go back and work through a few of Apple's tutorials here; your grasp of the frameworks seems tenuous, at best.