How to call one xib file from another class,ios - ios

I have googled a lot, but some where I am doing a mistake regarding the xib file. I have four buttons in view controller.xib file. Then when I tap the button one two three, alertinputtypetext has to be dislayed. Its done successfully.
But when i tap the fourth button, I need to display pickerView.xib. But when I am debugging the application, the application sequence is missing and showing the main.m class.
Please help me somebody. Give me hint to proceed further.

"I need to display the another file pickerView.xib" ?.. if pickerView is UIViewController subclass you could show it simply .. if its just a nib file contains a pickerView , you could use loadNibNamed:(NSString *)name owner:(id)owner options:(NSDictionary *)options , but actually you don't need to put it in separate nib file .. xib can hold more than one view inside it , so you could use you original viewController.xib , or what I prefer is to it programmatically without loading it from xib.

Related

Can't add a subclass in XIB

I have a scroll view that loads a series of XIBS as pages. One of the XIBs (iPhoneFirstPage) is a UIView that has a twitter button that I would like to link to another ViewController in the XIB. The only problem is when I create a subclass of UIView to add an IBAction to the button, the subclass doesn't show up under the "Custom Class" drop down on the UIView. How would I do this? Is there a better way?
Save both files (Cmd + S) and try again.
Cmd+Shift+K to clean and try again.
Just type the name in--it should build fine assuming you've typed the right name and it can find the file.
Restart Xcode and try again.
Note: This is a list of 4 different things to try. Any single one of them should correct the problem individually--you shouldn't necessarily need to do all 4 things.

Knowing the exact method call when tap on iOS app

Is there any quick way to know which method is called when we do any activity on iOS app. I have the code but this is written by some other team and I am trying to find out the action that is happening when I tap on iPad. Is there any way to know about it. I tried putting break points but it does not help.
Following ways out of many can help you:
Find out all methods that have IBAction mention in the start in your .m file. Put a break point on them.
Goto .storyboard or .XIB file of your respective controller, in the right pane check Connection inspector. This inspector will be divided into two halves first belongs to IBOutlet, you have to check the second one which is IBAction. Find them in your .m file and put a break point on it.
Check .h file for any IBAction methods, find its implementation in .m and put a break point on it.
Trace any IBAction selector(s) specified via addTarget function.
Hope it can help!!

Open text file by tapping a view

I have some basic questions. During launching, my app is looking for text files created in application and adds views that represent these files. Simple. I have information about file name, location etc.
Now I want to open a file by taping on a view. Does someone know the best way to open file? I can set Tag property of a view by adding file path. I can subview the UIView class, but don't know which solution is the best :)
Just how to open the file?
You could use enum and set tag to UIView or UIView subclasses (UIButton), and use switch-case to check if the correct view was tapped.
To manipulate with files use NSFileManager: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html

additional NIB for view controller in tabbed app

{Xcode 4.2, deployment target iOS4.3, not storyboard, using ARC}
I started with a tabbed application template & chose the universal platform, which nicely gives me view controller classes & NIB files for an iPhone (ClassName_iPhone.xib) & an iPad (ClassName_iPad.xib) for 2 tabs, with an if statement in the AppDelegate to determine which to run - exactly how I wanted it set up.
I wanted to add a 3rd & 4th tabs, so starting with the 3rd tab (doing 1 at a time) I created a new UIViewController subclass. As it doesn't give the option to create both NIBs at once, I selected "Targeted for iPad", & had intended to create the iPhone NIB manually. I added a "_iPad" suffix to the created NIB file, then I created a user interface view NIB file to which I added the "_iPhone" suffix. I then set up the code for the new view controller in the AppDelegate implementation file to include the 3rd view controller & tab, & I used the other view controller classes as a guide to set up the new class's code.
For the 3rd _iPhone NIB, I dragged a view object from the objects library onto the canvas, & set it up as per the other 2 _iPhone NIBs. But when I went to connect the outlets, there is no view outlet in the referencing outlets of the connections panel to connect with, which I thought there should be. At this point I suspected something was wrong.
I tried running it in the simulator, in iPad mode it works fine (all 3 tabs are clickable). But in iPhone mode clicking the 3rd tab crashes it with a "SIGABRT" on thread 1. It's obvious what I did didn't work. I don't see anything in the output window that gives me any clues.
Being a newbie to obj-c, so not being too sure of the problem, I would have thought that I either:
have used the wrong user interface template (view)
should have used a view controller object from the object library
(not a view)
or that I should have declared some outlets in my view controller
class files.
But if I should have done either of the latter 2, then my question would be why does the iPad NIB work then, when it clearly has a view object in the NIB & no outlets declared in the class files (same with the other 2 view controllers for both devices)?
Does the UITabView class somehow have outlets pre-declared within it for the first 2 tabs? But that still doesn't explain why the _iPad NIB works.
As usual, any help & advice much appreciated, & if there's a link to an explanation somewhere that I've missed, please show me, because I'm happy to do the research.
If what I've done wrong here is not determinable, then I guess ultimately what I'm asking is a clue to how best to create the second NIB file for iPhone to mesh with the class created with iPad NIB.
Sorry to answer my own question but with further searching I found this answer that was the solution, although not quite the whole story. So I thought to put what I did in an asnwer so others can refer to it.
As Piotr Czapla explains in the linked answer, for some reason Xcode doesn't populate the connectionRecords data, as you can see by my first red arrow. Having a look at the view controller that works (where second red arrow is), that's what the data should look like. So the answer is to cut the data & paste it into the NIB file, or type it. You can do this in Xcode by right-clicking the NIB file in the project navigatior & then Open As > Source Code, which is what you see in my screenshots.
The bit I want to add to Piotr Czapla's explanation though is the destination reference pointed to by the second red arrow might not be correct for the NIB file you're pasting into (mine wasn't) & Xcode might not let you go back into IB mode. If so, you need to get the correct reference from the IBUIView class within your NIB file, as pointed to by the third red arrow. Once I copied that reference to my destination reference ref=, as shown by the fourth red arrow, all was ok & the problem was solved. I could then go back into IB mode (right click, Open As > Interface Builder - iOS) & the view works in the simulator.

iOS: loading a UIView inside another UIView

I am trying to load a UIView inside another view.
view01 is set to take 50% vertical space on the main view. view01 is attached to an outlet. I will be using view01 to load various views on top of it. Now I am able to load view02 from an alternate xib file.
The problem is that sometimes it works and some times it doesn't. And it's doing this without any change to the data used in the app. So I am wondering what could be the reason for this intermittent problem?
This is the code to load:
statsView = [[StatsViewController alloc] initWithNibName:#"StatsViewController" bundle:nil];
[statsView setRiftIndex:riftIndex.characterSheet];
[statsView activateEditing:NO];
[listView addSubview:statsView.view];
Can't post images yet :(
The StatsViewController.xib has the StatsViewController class as the file-owner in the xib.
I finally found the problem. there was 2 xib files with the same name, one was from a previous test I had done. and the linker would alternate from one to the other every time I ran it. I was sure I had deleted the file before but it seams I had only removed the reference.

Resources