loadnibnamed

Why “loadNibNamed” methods return array?

半城伤御伤魂 提交于 2019-12-20 03:12:31
问题 When we use the loadNibNamed method to get nib file, why will return a array, is not a nib file name corresponds to a nib file? I try to print this array's count, I found it always return 1. I hope you can help me to explain, thank you every much! Here is the snippet of code : NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TestView" owner:self options:nil]; NSLog(@"array's count is %ld",array.count); 回答1: This is because NIB/xib files can also contain more than one view representation

iOS loadNibNamed confusion, what is best practice?

半城伤御伤魂 提交于 2019-12-17 22:39:22
问题 I'm familiar with most of the process of creating an XIB for my own UIView subclass, but not everything is working properly for me - it's mostly to do with the IBOutlets linking up. I can get them to work in what seems like a roundabout way. My setup is this: I have MyClass.h and MyClass.m. They have IBOutlets for a UIView (called view) and a UILabel (called myLabel). I added the 'view' property because some examples online seemed to suggest that you need this, and it actually solved an issue

A view loaded from the nib doesn't receive touch events

倾然丶 夕夏残阳落幕 提交于 2019-12-08 13:01:56
问题 I am trying to load a a view from the nib and add it to the main view. Here is my code. I loaded the nib in the initWithFrame of the @interface AddTaskView:UIView : - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { NSLog(@"init with frame"); // Initialization code NSArray *addTaskArrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"AddTaskView" owner:self options:nil]; self=[addTaskArrayOfViews objectAtIndex:0]; } return self; } After that I init the view and

Possible crash when loadNibNamed on jailbreak devices [UIDeviceRGBColor superview]: unrecognized selector

两盒软妹~` 提交于 2019-12-08 02:25:39
问题 My code looks like this: CGRect screenRect = [[UIScreen mainScreen] bounds]; SomeView *infoView; if(screenRect.size.height != 568.0){ // iPhone 5/5s users crash in the next line infoView = [[[NSBundle mainBundle] loadNibNamed:@"SomeViews" owner:self options:nil] objectAtIndex:1]; }else{ infoView = [[[NSBundle mainBundle] loadNibNamed:@"SomeViews" owner:self options:nil] objectAtIndex:0] } However, I get some crash reports from Crashlytics for iPhone 5/5s users as comment in the above code. I

loadNibName method is too slow - how to make it quicker?

主宰稳场 提交于 2019-12-01 20:18:04
问题 I have a scroll view, which contains about 40-50 objects of different types. The object's types are defined in function of the object's location (for ex. if is the 5th object in the scroll view-> is's Object1, if it is the 11th object in the scroll view -> it's Object2 type etc.). With a for I am verifying each element of an array, and then putting them into the scroll view, with this method: for (int i = 0; i < [myArray count]; i++){ if (i < 10){ NSArray *xib = [[NSBundle mainBundle]

iOS loadNibNamed confusion, what is best practice?

六月ゝ 毕业季﹏ 提交于 2019-11-28 20:27:14
I'm familiar with most of the process of creating an XIB for my own UIView subclass, but not everything is working properly for me - it's mostly to do with the IBOutlets linking up. I can get them to work in what seems like a roundabout way. My setup is this: I have MyClass.h and MyClass.m. They have IBOutlets for a UIView (called view) and a UILabel (called myLabel). I added the 'view' property because some examples online seemed to suggest that you need this, and it actually solved an issue where I was getting a crash because it couldn't find the view property, I guess not even in the UIView